A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5095 below:

[apex] ApexUnitTestShouldNotUseSeeAllDataTrue false negative due to casing (regression in PMD 7) ยท Issue #5095 ยท pmd/pmd ยท GitHub

Affects PMD Version: 7.3.0

From what I can gather, this is a regression from 6.55.0.

Description:

Rule: ApexUnitTestShouldNotUseSeeAllDataTrue

This is a bug/regression that I have noticed with the ApexUnitTestShouldNotUseSeeAllDataTrue rule. My immediate suspicion here is that it could be caused by either the new apex-parser or Summit-AST dependencies.

Apex annotations are case-insensitive, as are annotation attributes. PMD 6.55.0 correctly picks up and flags all case combinations for the @IsTest(SeeAllData=true)/@isTest(seeAllData=true) attribute, however in PMD 7 (I'm using 7.3.0) this doesn't seem to be the case, and @IsTest annotations with uppercase SeeAllData=true attributes are ignored (not flagged by PMD).

Annotation PMD 6.55.0 PMD 7.3.0 @IsTest(SeeAllData=true) ๐ŸŸข ๐Ÿ”ด @isTest(SeeAllData=true) ๐ŸŸข ๐Ÿ”ด @IsTest(seeAllData=true) ๐ŸŸข ๐ŸŸข @isTest(seeAllData=true) ๐ŸŸข ๐ŸŸข @IsTest(SeeAllData=True) ๐ŸŸข ๐Ÿ”ด @isTest(SeeAllData=True) ๐ŸŸข ๐Ÿ”ด @IsTest(seeAllData=True) ๐ŸŸข ๐ŸŸข @isTest(seeAllData=True) ๐ŸŸข ๐ŸŸข

I've posted an example Apex test file and PMD config below to demonstrate the issue. The output is different on PMD 7 (incorrect) vs 6.55.0.

Exception Stacktrace:

// Stacktrace not applicable!

Code Sample demonstrating the issue:

ruleset.xml
<?xml version="1.0" encoding="utf-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="6.55.0 Everything" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0">
<description>Example ruleset for GH</description>
<rule ref="category/apex/bestpractices.xml/ApexUnitTestShouldNotUseSeeAllDataTrue" />
</ruleset>
apex.cls
@isTest(SeeAllData = true)
public class SomeTest {

    @IsTest(SeeAllData=true)
    public static void testMethod1() {
        System.assertEquals(1 + 2, 3);
    }

    @isTest(SeeAllData=true)
    public static void testMethod2() {
        System.assertEquals(1 + 2, 3);
    }

    @IsTest(seeAllData=true)
    public static void testMethod3() {
        System.assertEquals(1 + 2, 3);
    }

    @isTest(seeAllData=true)
    public static void testMethod4() {
        System.assertEquals(1 + 2, 3);
    }

    @IsTest(SeeAllData=True)
    public static void testMethod5() {
        System.assertEquals(1 + 2, 3);
    }

    @isTest(SeeAllData=True)
    public static void testMethod6() {
        System.assertEquals(1 + 2, 3);
    }

    @IsTest(seeAllData=True)
    public static void testMethod7() {
        System.assertEquals(1 + 2, 3);
    }

    @isTest(seeAllData=True)
    public static void testMethod8() {
        System.assertEquals(1 + 2, 3);
    }

}

Steps to reproduce:

Run PMD 6.55.0 and 7.3.0 against the code sample above. Compare the output:

6.55.0:
java -classpath "/Users/henry/PMD/pmd-bin-6.55.0/lib/*" net.sourceforge.pmd.PMD -d "/Users/henry/PMD/src" -R "/Users/henry/PMD/ruleset/ruleset.xml" -r "/Users/henry/PMD/output/out.txt"

Contents of out.txt:

/Users/henry/PMD/src/apex.cls:2:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:5:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:10:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:15:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:20:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:25:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:30:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:35:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:40:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)

7.3.0:
java -classpath "/Users/henry/PMD/pmd-bin-7.3.0/lib/*" net.sourceforge.pmd.cli.PmdCli check -d="/Users/henry/PMD/src" -R="/Users/henry/PMD/ruleset/ruleset.xml" -r="/Users/henry/PMD/output/out.txt" -v

Contents of out.txt:

/Users/henry/PMD/src/apex.cls:15:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:20:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:35:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)
/Users/henry/PMD/src/apex.cls:40:	ApexUnitTestShouldNotUseSeeAllDataTrue:	Apex unit tests should not use @isTest(seeAllData = true)

Running PMD through/bug is reproducible from: CLI

Java runtime:

openjdk version "21.0.3" 2024-04-16
OpenJDK Runtime Environment Homebrew (build 21.0.3)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.3, mixed mode, sharing)

If there is any more information I can provide please let me know. Thank you for your continued work on PMD, it's an excellent tool.


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