-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
Product Area
A Rule
Your Need or Problem
When working Apex test classes, there is no automated way to enforce that developers specify the testFor property on the @IsTest annotation (e.g., @IsTest(testFor='ApexClass:MyService')).
The testFor parameter was introduced to explicitly link a test class to the class it covers, improving traceability, code coverage mapping, and maintainability.
Your Desired Solution
Add a new PMD rule under the bestpractices category that:
Triggers when an Apex class is annotated with @IsTest (or @isTest) at the class level but does not include the testFor property.
Passes when @IsTest(testFor='ApexClass:ClassName') (or any valid testFor value) is present.
Has a configurable severity (defaulting to Warning/Moderate).
Alternatives Considered
No response
Additional Context (Screenshots, Files, etc)
Example of violation:
@IsTest // ← missing testFor
public class MyServiceTest { ... }
Example passing:
@IsTest(testFor='ApexClass:MyService')
public class MyServiceTest { ... }
### Workaround
_No response_
### Urgency
Low
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels