Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] New Rule: JUnit5TestNoPrivateModifier #3288

Open
adangel opened this issue May 21, 2021 · 1 comment
Open

[java] New Rule: JUnit5TestNoPrivateModifier #3288

adangel opened this issue May 21, 2021 · 1 comment
Labels
a:new-rule Proposal to add a new built-in rule

Comments

@adangel
Copy link
Member

adangel commented May 21, 2021

Proposed Rule Name: JUnit5TestNoPrivateModifier

Proposed Category: Error Prone

Description:
See discussion in #3239. The rule should flag test methods / test classes, that are private, since they can't be executed by JUnit(5).

Sonar has a similar rule: https://rules.sonarsource.com/java/tag/tests/RSPEC-5810

The rule "JUnit5TestNoPrivateModifier" would probably also apply to JUnit4, so the name could also be "JUnitTestWrongModifier" (for JUnit4, private, protected and no modifier would be flagged, for JUnit5 only private modifier would be flagged).

Code Sample: This should include code, that should be flagged by the rule. If possible, the "correct" code
according to this new rule should also be demonstrated.

class MyTest { // not public, that's fine
    @Test
    private void testBad() { } // private test methods don't work
    @Test
    void testGoodJunit5() { } // package private as expected for JUnit5
    @Test
    public void testGoodJunit4() { } // public test method for JUnit4
}

Possible Properties:

  • No properties. The rule should be smart enough to distinguish between JUnit5 and JUnit4 automatically.
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label May 21, 2021
@adangel
Copy link
Member Author

adangel commented May 21, 2021

@ajeans FYI - I've separated out the other rule into its own issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:new-rule Proposal to add a new built-in rule
Projects
None yet
Development

No branches or pull requests

1 participant