Proposed Rule Name: CorrectTestAnnotation
Proposed Category: Error Prone
Description:
Some projects use JUnit's @Test and other projects use TestNG's @Test. Sometimes both of these annotations are available on the classpath via dependencies. If a programmer picks the wrong one in an autocomplete popup, then they think the test case will be tested but in fact it will be ignored. Code review won't likely catch the problem since most people ignore the imports. Even if code coverage is being enforced, the programmer will struggle to figure out why their test case is not running.
Code Sample:
The following code compiles but never runs if the project is using TestNG.
import org.junit.Test;
@Test
public static void myTest()
{
}
The following code compiles but never runs if the project is using JUnit.
import org.testng.annotations.Test;
@Test
public static void myTest()
{
}
Properties:
- framework: should be one of [JUnit | TestNG]. It could default to JUnit since that seems to be more popular.
Proposed Rule Name: CorrectTestAnnotation
Proposed Category: Error Prone
Description:
Some projects use JUnit's
@Testand other projects use TestNG's@Test. Sometimes both of these annotations are available on the classpath via dependencies. If a programmer picks the wrong one in an autocomplete popup, then they think the test case will be tested but in fact it will be ignored. Code review won't likely catch the problem since most people ignore the imports. Even if code coverage is being enforced, the programmer will struggle to figure out why their test case is not running.Code Sample:
The following code compiles but never runs if the project is using TestNG.
The following code compiles but never runs if the project is using JUnit.
Properties: