Test declared with the testMethod keyword
ID |
apex.maintainability.unit_test_annotation |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Api Design |
Language |
Apex |
Description
Reports a test method declared with the legacy testMethod keyword instead of the @IsTest annotation.
Rationale
testMethod is the pre-annotation spelling and it carries none of the configuration the annotation takes: @IsTest(SeeAllData=false), @IsTest(isParallel=true) and the @TestSetup-based structure all expect the annotation form. A file that mixes the two also makes the test inventory harder to read, because a search for @IsTest misses the older methods entirely.
The following code illustrates the pattern detected by this rule:
@IsTest
private class OrderServiceTest {
// FLAGGED: Test declared with the testMethod keyword
static testMethod void legacyOne() {
System.assertEquals(1, 1, 'stays equal');
}
// FLAGGED: Test declared with the testMethod keyword
private static testMethod void legacyTwo() {
System.assertEquals(2, 2, 'stays equal');
}
@IsTest
static void modernOne() {
System.assertEquals(1, 1, 'stays equal');
}
}