Missing annotation @IsTest in test methods
Why is this an issue?
The testMethod keyword for declaring test methods has been deprecated by Salesforce. Using the @IsTest annotation is the recommended and widely adopted approach.
While both approaches currently work, using deprecated syntax:
May cause issues in future Salesforce releases
Reduces code consistency when mixed with modern patterns
Does not support additional annotation parameters like
@IsTest(SeeAllData=false)
Examples
Example of incorrect code:
private class AccountServiceTest {
static testMethod void testGetAccounts() {
// Test logic...
}
}
Example of correct code:
@IsTest
private class AccountServiceTest {
@IsTest
static void testGetAccounts() {
// Test logic...
}
}
How can I fix violations?
This rule supports autofix.
To manually fix violations:
Replace the
testMethodkeyword with the@IsTestannotation on the method.Add the
@IsTestannotation to the test class if it is not already present.
Resources
