codeql
codeql copied to clipboard
False positive, java/unused-reference-type and JUnit 5 classes
JUnit Tests using JUnit 5 are reported as java/unused-reference-type. This is because the JUnit 5 convention is to use package scoped class and method names. This rule should be checking for methods with JUnit annotations (e.g. @Test, @BeforeEach, @ParameterizedTest). The current check only looks for subsclassing of TestCase, which hasn't been applicable since JUnit 4.
Code samples or links to source code
Example test code that would be reported as unused.
class MyTest
{
@Test
void test()
{
// some test code.
}
}
Example false positive. https://github.com/real-logic/aeron/security/code-scanning/1583
Thanks for the report. That looks indeed like a false positive.
Hi there!
Is there a workaround for this issue?
Could be solved by adding the following check not dead.getAMethod() instanceof TestMethod and or not dead instanceof TestClass and?