-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Add new quality query to detect missing @Nested
annotation in JUnit5 tests
#19094
base: main
Are you sure you want to change the base?
Java: Add new quality query to detect missing @Nested
annotation in JUnit5 tests
#19094
Conversation
...ry-tests/Likely Bugs/Frameworks/JUnit/JUnit5NonStaticInnerClassMissingNestedAnnotation.qlref
Fixed
Show fixed
Hide fixed
8653c19
to
daad77a
Compare
…emplate when identifying JUnit 5 test methods
b207ce1
to
0f00262
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I have no preference on the problem.severity
.
I'll leave as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcogs33 👋🏻 - approving on behalf of Docs ⚡
Left a few minor suggestions, mainly to improve readability.
java/ql/src/Likely Bugs/Frameworks/JUnit/JUnit5MissingNestedAnnotation.ql
Outdated
Show resolved
Hide resolved
java/ql/src/Likely Bugs/Frameworks/JUnit/JUnit5MissingNestedAnnotation.md
Outdated
Show resolved
Hide resolved
|
||
## Implementation Notes | ||
|
||
This rule is focused on missing `@Nested` annotations on non-static nested (inner) test classes. Static nested test classes should not be annotated with `@Nested`. As a result, the absence of a `@Nested` annotation on such classes is compliant. Identifying incorrect application of a `@Nested` annotation to static nested classes is out of scope for this rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we say "query" instead of "rule"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered that as well, but found that there are many pre-existing qhelp files that use the term "rule" (see search results) so I left as-is.
I can change to "query" if anyone feels strongly about it. If we choose to say "query" instead, then we should align on that for all of the ported queries, since I think several say "rule". e.g. java/empty-method
Co-authored-by: mc <[email protected]>
Thanks @mchammer01! I've applied your suggestions. |
cc @knewbury01 |
Description
Adds a new quality query to detect missing
@Nested
annotations on JUnit 5 inner test classes. This query is migrated from the advance security team's quality queries.Consideration
Changes from original query. Let me know if you disagree with any of these changes:
not testClass.isStatic()
since the non-static requirement already seemed to be handled bytestClass instanceof InnerClass
. Let me know if the additional non-static check is needed for some reason I'm not aware of.@Nested
annotation on abstract classes is invalid and may cause an error. This exclusion reduces the number of alerts on the MRVA top-100 from 5 to 1 and on the MRVA top-1000 from 41 to 29.anonymous
,local
, andprivate
classes since JUnit seems to define an inner class as non-private, non-anonymous, and non-local. These exclusions further reduce the number of alerts on the MRVA top-100 from 1 to 0 and on the MRVA top-1000 from 29 to 25.@RepeatedTest
,@ParameterizedTest
,@TestFactory
, and@TestTemplate
when identifying JUnit 5 test methods. This inclusion adds 4 more results on the MRVA top-1000.testability
andframeworks/junit
metadata tags to align with the tags on the other queries injava/ql/src/Likely Bugs/Frameworks/JUnit
.Questions:
problem.severity
oferror
instead ofwarning
since it results in tests not running correctly?Other Notes: