Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] JUnitTestsShouldIncludeAssert: false negative with TestNG #4503

Closed
LynnBroe opened this issue Apr 24, 2023 · 0 comments · Fixed by #4507
Closed

[java] JUnitTestsShouldIncludeAssert: false negative with TestNG #4503

LynnBroe opened this issue Apr 24, 2023 · 0 comments · Fixed by #4507
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@LynnBroe
Copy link
Contributor

Affects PMD Version:7.0.0-rc1

Rule: JUnitTestsShouldIncludeAssert

Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/latest/pmd_rules_java_bestpractices.html#junittestsshouldincludeassert

Description:
The first code sample uses the annotations org.testng.annotations.*, and the second one uses org.junit.*. The analysis results of the two cases should be equivalent because these annotations are equivalent. However, PMD reports a warning in the second sample and no warnings in the first sample. PMD should report a warning in Case 1 like Case 2.

Code Sample demonstrating the issue:
Case 1

import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
public class A {
  @AfterClass
  @Test
  void test() {}  // report no warning
}

Case 2

import org.junit.jupiter.api.Test;
import org.junit.AfterClass;
public class B {
    @AfterClass
    @Test
    void test() {}  // report a warning
}

Expected outcome: The analysis results of the two classes should be the same and both should be reported a violation.

PMD reports no violation in the first class, but that's wrong. That's a false negative. PMD should treat testng like junit.

Running PMD through: CLI

@LynnBroe LynnBroe added the a:false-negative PMD doesn't flag a problematic piece of code label Apr 24, 2023
@adangel adangel changed the title [java]A false negative about JUnitTestsShouldIncludeAssert and testng [java] JUnitTestsShouldIncludeAssert: A false negative with TestNG May 11, 2023
@adangel adangel changed the title [java] JUnitTestsShouldIncludeAssert: A false negative with TestNG [java] JUnitTestsShouldIncludeAssert: false negative with TestNG May 11, 2023
@adangel adangel added this to the 7.0.0 milestone May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants