Test method declares parameters
ID |
apex.maintainability.test_methods_params |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Test Quality |
Language |
Apex |
Rationale
The test runner calls test methods with no arguments, so a test method with parameters is never executed as a test - it compiles, it is counted in no run, and its assertions never fire. The code it was written to cover then shows as uncovered, or worse, is covered by another test that does not assert the same thing, and the gap is invisible until a deployment fails on coverage.
The following code illustrates the pattern detected by this rule:
@IsTest
private class ParameterisedTest {
// FLAGGED: Test method declares parameters
@IsTest
static void checksName(String expected) {
System.assertEquals(expected, 'Acme', 'never runs');
}
// FLAGGED: Test method declares parameters
static testMethod void checksLegacy(Integer count) {
System.assertEquals(1, count, 'never runs');
}
@IsTest
static void checksNameProperly() {
Account a = new Account(Name = 'Acme');
System.assertEquals('Acme', a.Name, 'name is set');
}
private static Account buildAccount(String name) {
return new Account(Name = name);
}
}