Skip to content

[java] New Rule: WrongTestAnnotation #2846

@numeralnathan

Description

@numeralnathan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-ruleProposal to add a new built-in rule

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions