[java] New rule: JUnit5TestShouldBePackagePrivate#3247
Conversation
…vate' Add the rule to check that JUnit5 tests methods and classes are package private. Add unit tests
Generated by 🚫 Danger |
oowekyala
left a comment
There was a problem hiding this comment.
Welcome and thanks for your work on this! I have a couple of suggestions for improvements, please take a look and push new commits when you can
rather than the body declaration
|
@ajeans This new rule detects two violations in the spring-framework: https://chunk.io/pmd/0094edd7ef3f417898be43865c65ec41/diff/spring-framework/index.html#section-violations
Both are private static inner classes. Are these valid cases? Since they are private, I thought, they should only be picked up by the other (to be implemented) rule JUnit5TestNoPrivateModifier... Besides that, these two cases might be a false positive for JUnit5TestNoPrivateModifier anyway - but probably not so easy to detect. It seems, that they use So for this rule, I'd suggest to exclude private classes/methods, as this rule should only flag cases, where the class/method is public/protected. This should be possible by restricting the query additionally via |
|
Thanks for the feedbacl @adangel
It appears they are, those are inner static classes annotated with
Agreed, I added two unit tests and changed the rule to target protected and public modifiers, and ignore private modifiers.
That's using the jupiter engine dependency directly, so definitely advanced usage. The rule is targeted at devs that simply use the test annotations for simple and documented use cases. If you are doing the test discovery using an hardcoded list of test classes, you're way outside the junit user guide, and this rule doesn't make a lot of sense...
Done with latest commit, hope this is what you had in mind. |
Add the rule to check that JUnit5 tests methods and classes are package private.
Add unit tests
Describe the PR
Propose a codestyle rule for Jupiter / JUnit5 tests according to the feedback received from @adangel in the issue.
Not sure how to add the 'externalInfoURL', so simply pointed at the rule name, assuming that the site is generated from the XML rule file
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)