False positive report of UnusedMethod for methods used with JUnit 5 MethodSource annotation without explicitly provided factory method name
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
Error Prone 2.37.0 flags static method as unused if it's used only as a JUnit 5 MethodSource without explicitly mentioning it as a factory method.
```
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
class MyTest {
private enum MyEnum {
ALPHA,
BETA
}
@ParameterizedTest
@MethodSource
void testModification(MyEnum enumValue) {
System.out.println(enumValue);
}
private static MyEnum[] testModification() {
return MyEnum.values();
}
}
```
`[UnusedMethod] Method 'testModification' is never used.`
The [documentation](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests-sources-MethodSource) states:
> If you do not explicitly provide a factory method name via @MethodSource, JUnit Jupiter will search for a factory method that has the same name as the current @ParameterizedTest method by convention.
https://github.com/google/error-prone/issues/2335 was fixed so that only those factory methods that were otherwise unused but were explicitly mentioned in the @MethodSource were no longer false positives. That was not a complete fix.
Contributor guide
Assessment
This issue has not been assessed yet.