Overview
This rule flags Apex test methods that contain an insufficient number of Assertions. It's critical to have not just asserts, but meaningful Assertions. They're not just about hitting code coverage targets; they're about verifying that your test logic actually works as expected under all relevant conditions. Without enough assertions, your tests might pass, but they won't reliably confirm the correctness of your code.
Code Reviews classifies this as an Error because it indicates a gap in proper testing methodology, increasing the risk of undetected logical flaws and technical debt in your application.
Why This Matters
Tests lacking sufficient Assertions, or those designed merely to boost code coverage, can lead to:
Undetected Defects: Logic errors might exist in the code but remain undiscovered because the tests aren't explicitly verifying the expected outcomes.
False Sense of Security: Achieving high code coverage without robust Assertions can create a misleading impression of code quality and reliability.
Higher Maintenance Costs: When code breaks, it's harder to pinpoint the issue without precise Assertions indicating what went wrong.
Reduced Readability of Tests: Well-asserted tests serve as clear documentation of the expected behavior of the code being tested.
Compliance with Test Standards: Salesforce requires a minimum of 75% test coverage for deployment to production, but simply covering lines without proper Assertions undermines the intent of this safeguard.
What Triggers This Rule
Code Reviews flags Apex test methods where the number of Assertions falls below a configurable minimum threshold which is set to 1 by default.
How to Configure the Minimum Number of Assertions in Code Reviews
Code Reviews let you define the minimum number of Assertions or decisions required based on your team’s needs. To adjust the threshold that triggers this rule, go to the Resilient Policy, click the pencil icon, find the Insufficient number of Assertions rule, and click the pencil icon again to update the minimum required Assertions.
Recommended Approach
Always use Assertions in your test methods to explicitly validate that your logic produces the expected outcomes.
Summary
Testing solely for code coverage is a detrimental practice. Proper test methods must incorporate sufficient Assertions to confirm that the logic functions as intended in all relevant scenarios. Code Reviews flags the insufficient number of Assertions as an Error to encourage rigorous testing and a focus on validating actual functionality, thereby preventing hidden defects and improving the overall quality of your Salesforce applications.


