Java: Add new quality query to detect missing @Nested annotation in JUnit5 tests#19094
Merged
jcogs33 merged 20 commits intogithub:mainfrom Apr 22, 2025
Merged
Conversation
...ry-tests/Likely Bugs/Frameworks/JUnit/JUnit5NonStaticInnerClassMissingNestedAnnotation.qlref
Fixed
Show fixed
Hide fixed
8653c19 to
daad77a
Compare
added 11 commits
March 23, 2025 19:48
…emplate when identifying JUnit 5 test methods
b207ce1 to
0f00262
Compare
tamasvajk
previously approved these changes
Mar 24, 2025
Contributor
tamasvajk
left a comment
There was a problem hiding this comment.
LGTM, I have no preference on the problem.severity.
Contributor
Author
I'll leave as |
mchammer01
previously approved these changes
Mar 25, 2025
Contributor
mchammer01
left a comment
There was a problem hiding this comment.
@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
owen-mc
reviewed
Mar 25, 2025
java/ql/src/Likely Bugs/Frameworks/JUnit/JUnit5MissingNestedAnnotation.md
Show resolved
Hide resolved
Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com>
Contributor
Author
|
Thanks @mchammer01! I've applied your suggestions. |
Contributor
Author
|
cc @knewbury01 |
owen-mc
previously approved these changes
Apr 1, 2025
owen-mc
previously approved these changes
Apr 2, 2025
Contributor
owen-mc
left a comment
There was a problem hiding this comment.
Approved, modulo a few things which need to be cleared up before merging.
tamasvajk
approved these changes
Apr 22, 2025
owen-mc
approved these changes
Apr 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new quality query to detect missing
@Nestedannotations 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.@Nestedannotation 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, andprivateclasses 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@TestTemplatewhen identifying JUnit 5 test methods. This inclusion adds 4 more results on the MRVA top-1000.testabilityandframeworks/junitmetadata tags to align with the tags on the other queries injava/ql/src/Likely Bugs/Frameworks/JUnit.Questions:
problem.severityoferrorinstead ofwarningsince it results in tests not running correctly?Other Notes: