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] TestClassWithoutTestCases false positive with JUnit5 ParameterizedTest #2636

Closed
andreoss opened this issue Jul 9, 2020 · 3 comments · Fixed by #4162
Closed

[java] TestClassWithoutTestCases false positive with JUnit5 ParameterizedTest #2636

andreoss opened this issue Jul 9, 2020 · 3 comments · Fixed by #4162
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@andreoss
Copy link
Contributor

andreoss commented Jul 9, 2020

Affects PMD Version: 6.10.0

Rule: TestClassWithoutTestCases

Description:

When a test class is extended from some parent class, the following check is triggered:
This class name ends with Test but contains no test cases (TestClassWithoutTestCases)
Probably its being misidentified as Junit 3.

final class SampleTest extends Object {

    @ParameterizedTest
    @ValueSource(ints = {1})
    void doesTest(final int num) {
        Assertions.assertTrue(num > 0);
    }
}

Test class which has no parent works fine, but empty class is not producing an error too (probably worth a separate issue).

final class SampleTest {
}

Expected outcome:

No error occurs when @ParameterizedTest is used inside a test class with a parent.

@andreoss andreoss added the a:bug PMD crashes or fails to analyse a file. label Jul 9, 2020
@LiGaOg
Copy link

LiGaOg commented Apr 5, 2022

Please assign this issue to me

@BillyBolton
Copy link

Any status on this issue?

@adangel adangel changed the title [java] Junit 5 and TestClassWithoutTestCases [java] TestClassWithoutTestCases false positive with JUnit5 Oct 14, 2022
@adangel adangel added a:false-positive PMD flags a piece of code that is not problematic and removed a:bug PMD crashes or fails to analyse a file. labels Oct 14, 2022
@adangel
Copy link
Member

adangel commented Oct 15, 2022

I couldn't reproduce this false-positive when using the auxclasspath option (typeresolution). Only when running PMD on an non-compiled project without auxclasspath, this violation was reported. And with the current version (PMD 6.50.0, actually since PMD 6.27.0) it is not reported even without auxclasspath.

However, looking at the implementation of TestClassWithoutTestCases - the impl doesn't support "ParameterizedTest". So there are two problems:

  1. ParameterizedTest is not supported (and some other annotations from JUnit5)
  2. Empty classes are not detected - this is a false negative, see the older issue [java] Inconsistent results with TestClassWithoutTestCases #929

I'm trying to fix both issues.

@adangel adangel changed the title [java] TestClassWithoutTestCases false positive with JUnit5 [java] TestClassWithoutTestCases false positive with JUnit5 ParameterizedTest Oct 15, 2022
@adangel adangel added this to the 6.51.0 milestone Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants