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

Description

Reports a method annotated @IsTest, or declared with testMethod, that takes parameters.

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);
    }
}

Remediation

Remove the parameters and build the data inside the method, or in a @TestSetup method. If the intent was a shared helper, drop the @IsTest annotation from it and call it from the real test methods.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved