GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] TestClassWithoutTestCases false positive with JUnit5 ParameterizedTest · Issue #2636 · pmd/pmd

[java] TestClassWithoutTestCases false positive with JUnit5 ParameterizedTest #2636

New issue
Copy link
New issue
Copy link
Closed
#4162
Closed
[java] TestClassWithoutTestCases false positive with JUnit5 ParameterizedTest#2636
#4162
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.51.0

Description

@andreoss
andreoss
opened on Jul 9, 2020
Issue body actions

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.

Activity

  1. andreoss
    added
    a:bugPMD crashes or fails to analyse a file.
    on Jul 9, 2020
  2. LiGaOg commented on Apr 5, 2022

    @LiGaOg
    LiGaOg
    on Apr 5, 2022
    More actions

    Please assign this issue to me

  3. adangel
    assigned
    LiGaOg
    on Apr 5, 2022
  4. BillyBolton commented on Sep 21, 2022

    @BillyBolton
    BillyBolton
    on Sep 21, 2022
    More actions

    Any status on this issue?

  5. adangel
    unassigned
    LiGaOg
    on Oct 14, 2022
  6. adangel
    changed the title [-][java] Junit 5 and TestClassWithoutTestCases[/-] [+][java] TestClassWithoutTestCases false positive with JUnit5[/+] on Oct 14, 2022
  7. adangel
    added
    a:false-positivePMD flags a piece of code that is not problematic
    and removed
    a:bugPMD crashes or fails to analyse a file.
    on Oct 14, 2022
  8. adangel commented on Oct 15, 2022

    @adangel
    adangel
    on Oct 15, 2022
    Member
    More actions

    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.

  9. adangel
    changed the title [-][java] TestClassWithoutTestCases false positive with JUnit5[/-] [+][java] TestClassWithoutTestCases false positive with JUnit5 ParameterizedTest[/+] on Oct 15, 2022
  10. adangel
    added a commit that references this issue on Oct 15, 2022

    [java] Improve TestClassWithoutTestCases

    This issue will close once commit 33ede7f is merged into the 'main' branch.
    33ede7f
  11. adangel
    added this to the 6.51.0 milestone on Oct 15, 2022
  12. adangel
    closed this as completedin #4162on Oct 28, 2022
  13. adangel
    closed this as completedin 33ede7fon Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.51.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.