Skip to content

[apex] Fix #6988: Add ApexUnitTestClassShouldHaveRunRelevantTestsAnnotation rule - #6991

Merged
adangel merged 12 commits into
pmd:mainfrom
tprouvot:feature/apexUnitTestClassShouldHaveRunRelevantTestsAnnotation
Sep 21, 2026
Merged

adangel merged 12 commits into
pmd:mainfrom
tprouvot:feature/apexUnitTestClassShouldHaveRunRelevantTestsAnnotation

Conversation

@tprouvot

@tprouvot tprouvot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Describe the PR

  • Adds a new Apex best practice rule ApexUnitTestClassShouldHaveRunRelevantTestsAnnotation that flags test classes missing either the critical or testFor modifier on the @IsTest annotation.
  • These modifiers are required to opt in to Salesforce's RunRelevantTests deployment test level (API v66.0+, Beta).
  • Classes whose companion *-meta.xml declares an API version older than 66.0 are not flagged, since the modifiers aren't available to them.
  • Classes whose API version could not be determined are still flagged (fail-safe).

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)
  • Added (in-code) documentation (if needed)

tprouvot and others added 3 commits August 19, 2026 15:59
…ShouldHaveRunRelevantTestsAnnotation rule to check for 'critical' and 'testFor' modifiers based on API version. Add method to retrieve API version from companion metadata XML.
…d remove unnecessary whitespace. Update test class visibility from public to package-private.
@pmd-actions-helper

pmd-actions-helper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 78 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-09-21 18:18:15+00:00 for ef74377)

@tprouvot

Copy link
Copy Markdown
Contributor Author

Hi @adangel
If you need anything about the context of this PR feel free to ask (in particular things related to apiVersion that are specific to Salesforce)

@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Aug 22, 2026

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Please verify the behavior, when there are additional annotations and not just @IsTest.

Also, we might need to have tests, that mark individual test cases as "critical", if that's a thing...

tprouvot and others added 6 commits August 24, 2026 09:31
…practices/ApexUnitTestClassShouldHaveRunRelevantTestsAnnotationRule.java

Co-authored-by: Andreas Dangel <[email protected]>
…filter annotation parameters by 'IsTest' annotation. Update test XML to include new test case for class using critical=true with additional annotation.
…ionTest by removing dependency on PmdRuleTst class to simplify test structure.
@tprouvot

Copy link
Copy Markdown
Contributor Author

Hi @adangel,
Did you had a chance to review my last comment ?

@adangel

adangel commented Sep 21, 2026

Copy link
Copy Markdown
Member

Did you had a chance to review my last comment ?

I've created #7093 to track the version enhancement.

@adangel adangel added this to the 7.28.0 milestone Sep 21, 2026
@adangel adangel changed the title [apex] Add ApexUnitTestClassShouldHaveRunRelevantTestsAnnotation rule [apex] Fix #6988: Add ApexUnitTestClassShouldHaveRunRelevantTestsAnnotation rule Sep 21, 2026

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adangel
adangel merged commit 6b4a2cf into pmd:main Sep 21, 2026
13 checks passed
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.

[apex] New rule: Detect usage of @IsTest(critical=true) / @IsTest(testFor='...') annotations (RunRelevantTests, Beta, API 66.0+)

2 participants