Test coverage padding method
Why is this an issue?
Salesforce requires a minimum of 75% test coverage before deploying code to a production environment. This safeguard protects customers and helps keep their applications resilient. Some developers use workarounds to artificially boost test coverage by introducing dummy code into production classes—methods that exist solely to be called by tests and inflate coverage numbers.
This rule detects production methods that appear to serve no purpose other than padding test coverage—methods that are large, contain little meaningful logic, and are only ever called by tests.
Such methods are detrimental to code quality and undermine the purpose of Salesforce's coverage requirements.
Examples
Example of incorrect code:
public class AccountService {
// This method does nothing useful - it just pads coverage
public void padCoverage() {
Integer i = 0;
i++;
i++;
i++;
// ... repeated many times to inflate line count
i++;
i++;
}
public void processAccounts(List<Account> accounts) {
// Actual business logic here
}
}
@IsTest
private class AccountServiceTest {
@IsTest
static void testPadCoverage() {
// Calls the padding method to get easy coverage
new AccountService().padCoverage();
}
}
Example of correct code:
public class AccountService {
public void processAccounts(List<Account> accounts) {
if (accounts == null || accounts.isEmpty()) {
throw new IllegalArgumentException('Accounts list cannot be null or empty');
}
for (Account acc : accounts) {
acc.Status__c = 'Processed';
}
update accounts;
}
}
@IsTest
private class AccountServiceTest {
@IsTest
static void testProcessAccountsWithValidData() {
Account testAccount = new Account(Name = 'Test');
insert testAccount;
Test.startTest();
new AccountService().processAccounts(new List<Account>{testAccount});
Test.stopTest();
Account result = [SELECT Status__c FROM Account WHERE Id = :testAccount.Id];
Assert.areEqual('Processed', result.Status__c, 'Status should be updated');
}
// Also add tests for null and empty cases to get complete coverage
}
How can I fix violations?
Remove the padding method: If the method serves no real purpose, delete it entirely.
Improve test quality: Focus on testing real functionality rather than artificially inflating coverage numbers.
Resources
