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] JUnit 4 false positives for JUnit 5 tests #940

Closed
AdamCarroll opened this Issue Feb 26, 2018 · 1 comment

Comments

Projects
None yet
4 participants
@AdamCarroll

AdamCarroll commented Feb 26, 2018

Affects PMD Version:

6.1.0

Rule:

  • JUnit4TestShouldUseBeforeAnnotation
  • JUnit4TestShouldUseAfterAnnotation
  • JUnit4TestShouldUseTestAnnotation

Description:

JUnit 4 rules cause false positive in JUnit 5 tests. It looks like the new annotations for JUnit 5 aren't being handled as they should be.

Code Sample demonstrating the issue:

The file FileFormatType on the project VocabHunter shows this problem. To work around the problem, the following lines have been added to ruleset.xml:

<rule ref="category/java/bestpractices.xml">
    <exclude name="JUnit4TestShouldUseBeforeAnnotation"/>
    <exclude name="JUnit4TestShouldUseAfterAnnotation"/>
    <exclude name="JUnit4TestShouldUseTestAnnotation"/>
</rule>

To reproduce the problem, remove the above workaround line and then launch the following:

$ ./gradlew clean :core:pmdTest

Running PMD through: Gradle

@vovkss

This comment has been minimized.

Contributor

vovkss commented Jul 25, 2018

I've faced the same problem after upgrade to JUnit5 and PMD 6.5.

Here a pull request proposal which would solve the problem: https://github.com/pmd/pmd/pull/1256/files

@adangel adangel added this to the 6.7.0 milestone Jul 29, 2018

@jsotuyod jsotuyod added the has:pr label Aug 4, 2018

vovkss added a commit to vovkss/pmd that referenced this issue Aug 6, 2018

vovkss added a commit to vovkss/pmd that referenced this issue Aug 6, 2018

vovkss added a commit to vovkss/pmd that referenced this issue Aug 6, 2018

Add tests UseAssertEqualsInsteadOfAssertTrue,UseAssertNullInsteadOfAs…
…sertTrue,UseAssertSameInsteadOfAssertTrue,UnnecessaryBooleanAssertion (pmd#940)

vovkss added a commit to vovkss/pmd that referenced this issue Aug 6, 2018

Add tests UseAssertEqualsInsteadOfAssertTrue,UseAssertNullInsteadOfAs…
…sertTrue,UseAssertSameInsteadOfAssertTrue,UnnecessaryBooleanAssertion (pmd#940)

adangel added a commit that referenced this issue Aug 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment