Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3351

Rule S5826: Methods setUp() and tearDown() should be correctly annotated starting with JUnit4

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.5
    • Component/s: Rules

      Description

      S2391 is targetting only JUnit 3, by reporting bad declaration of suite, setUp and tearDown.

      From JUnit 3 to 4, the logic for these three methods changed, that could lead to a confusing declaration that the rule could report:

      • Method public void setUp() or public void tearDown() declared in JUnit 4/5 context without corresponding annotation.
        Should be declared with @Before/@After or named differently.
      • Method public static Test suite().
        will do nothing, not the correct way to aggregate tests. Correct way in JUnit4.

      It would help to migrate from JUnit3 and avoid confusing usage.

      Revert changes tentatively introduced to improve RSPEC-2391, and implement a new rule RSPEC-5826 instead.
      When implementing RSPEC-5826, RSPEC-2391 should be reviewed to check if it should be deprecated or not.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: