Skip to content

[java] Fix #2846: New Rule: WrongTestAnnotation#6735

Merged
UncleOwen merged 2 commits into
pmd:mainfrom
UncleOwen:issue-2846-new-rule-use-correct-test-annotation
Jun 3, 2026
Merged

[java] Fix #2846: New Rule: WrongTestAnnotation#6735
UncleOwen merged 2 commits into
pmd:mainfrom
UncleOwen:issue-2846-new-rule-use-correct-test-annotation

Conversation

@UncleOwen

Copy link
Copy Markdown
Member

Describe the PR

The new Java rule WrongTestAnnotation detects when test annotations from the wrong testing framework (JUnit 4, JUnit Jupiter, or TestNG) are used in your code, preventing tests from being silently skipped due to framework mismatches. This helps avoid the silent failure where tests compile but don't execute because the test runner doesn't recognize the annotation.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • [n/a] Added (in-code) documentation (if needed)

@UncleOwen UncleOwen force-pushed the issue-2846-new-rule-use-correct-test-annotation branch from 00135c9 to 53a3723 Compare May 29, 2026 13:54
@pmd-actions-helper

pmd-actions-helper Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 349 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-06-03 16:47:42+00:00 for cd424ac)

@UncleOwen UncleOwen force-pushed the issue-2846-new-rule-use-correct-test-annotation branch from 53a3723 to cd424ac Compare June 3, 2026 16:30
@zbynek

zbynek commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

As a rule focused on annotations this looks good.
IntelliJ tends to also suggest not using any JUnit 4 classes in Junit Jupiter tests, e.g. Assert should be replaced with Assertions. But maybe those would be better covered by a separate rule, since there are more assertion frameworks than test frameworks.

@UncleOwen

Copy link
Copy Markdown
Member Author

Yeah, that could be another rule.

@UncleOwen UncleOwen added this to the 7.26.0 milestone Jun 3, 2026
@UncleOwen UncleOwen merged commit 2b8a33c into pmd:main Jun 3, 2026
13 checks passed
@UncleOwen UncleOwen deleted the issue-2846-new-rule-use-correct-test-annotation branch June 3, 2026 19:51
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] New Rule: WrongTestAnnotation

3 participants