In order to protect shared resources, Salesforce enforces a maximum number of SOQL queries, DML queries, ``++@future++`` method, etc... execution inside a single https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_transaction.htm[transaction]. This is part of https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm[Governor limits].
Every test method should check how close the tested code is to reach the governor limits. This is done by calling ``++Test.StartTest()++`` before the tested code and ``++Test.StopTest()++`` after it.
This rule raises an issue when a test method, i.e. a method annotated with ``++@isTest++`` or ``++testmethod++``, does not contain a call to ``++Test.StartTest()++`` and ``++Test.StopTest()++``.
No issue will be raised if the test class, i.e. the class annotated with ``++@isTest++``, contains helper methods, i.e. methods not annotated with ``++@isTest++`` or ``++testmethod++``, which contain calls to ``++Test.StartTest()++`` or ``++Test.StopTest()++``. This indicates that the test code has been factorised and the rule would raise false positives.
=== on 5 Jul 2019, 17:28:50 Nicolas Harraudeau wrote:
If we raise false positives a possible exception would be:
=== Exceptions
No issue will be raised if the test class, i.e. the class annotated with ``++@isTest++``, contains helper methods, i.e. methods not annotated with ``++@isTest++`` or ``++testmethod++``, which contain calls to ``++Test.StartTest()++`` or ``++Test.StopTest()++``. This indicates that the test code has been factorised and the rule would raise false positives.
=== on 8 Aug 2019, 09:32:02 Quentin Jaquier wrote:
SONARSLANG-397shows that, even with the exception above, we have a lot of issue, with potential false positives.
We decided to keep the rule, but remove it from the default quality profile.