Minimum number of assertions

Enforce a requirement on the minimum number of assertions for any test methods.

Lorenzo Frattini avatar
Written by Lorenzo Frattini
Updated over a week ago


Aiming at coverage, for coverage's sake is a bad practice. Test should use assertions properly, to ensure logic works as expected in all the relevant circumstances.


  • Minimum number of assertions. The number of assertions that you need to be present on each test method. Any number below this threshold will trigger a detection.


  • Apex test methods that don't contain sufficient number of System.assert or equivalent

Using FinancialForce's ApexMock library

Invocations of the fflib_ApexMocks.verify method are treated as valid assertions by this rule.

// Given
fflib_ApexMocks mocks = new fflib_ApexMocks();
fflib_MyList.IList mockList = (fflib_MyList.IList)mocks.mock(fflib_MyList.class);

// When

// Then
((fflib_MyList.IList) mocks.verify(mockList)).add('bob');
((fflib_MyList.IList) mocks.verify(mockList, fflib_ApexMocks.NEVER)).clear();
Did this answer your question?