Affects PMD Version: 7.6.0
Rule: ApexUnitTestShouldNotUseSeeAllDataTrue
Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/pmd-doc-7.6.0/pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrue
Description:
We have configured hard gates for the ApexUnitTestShouldNotUseSeeAllDataTrue rule within our SFDC Code Scan tool registry. However, a class deployed on January 9, 2025, contained this vulnerability, and the Code Scan rule engine failed to identify the error.
After performing the analysis we observed that it is an expected behaviour of the plugin and as we noticed that in the class where this scan was missed, there was single quotation mark for seealldata = 'true'. As mentioned above, the PMD scanner behavior regarding the SeeAllData annotation is determined by how the annotation value is defined in the code. After analyzing the PMD rule implementation for ApexUnitTestShouldNotUseSeeAllDataTrue, we identified that the scan only detects violations when the annotation value is explicitly set as a Boolean (true).
Code Sample demonstrating the issue: https://github.com/pmd/pmd/blob/main/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestShouldNotUseSeeAllDataTrueRule.java
@isTest(seeAllData = 'true') public class Foo { public static testMethod void testSomething() { Account a = null; // This is better than having a NullPointerException // System.assertNotEquals(a, null, 'account not found'); a.toString(); } }
Expected outcome:
When SeeAllData is assigned as a single, the rule should trigger.
PMD should report a violation at line ..., but doesn't, this is because the underlying implementation uses ASTAnnotationParameter , which evaluates the enclosed annotation value strictly as a Boolean.. This is a false-negative.
Running PMD through: CLI,CI/CD Tools
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4