A RetroSearch Logo

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

Search Query:

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

[apex] ApexUnitTestMethodShouldHaveIsTestAnnotation false positive with helper method · Issue #3183 · pmd/pmd · GitHub

Affects PMD Version:
6.32.0

Rule:
ApexUnitTestMethodShouldHaveIsTestAnnotation

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation

Description:

Code Sample demonstrating the issue:

@isTest 
public class TestFactory {
    @isTest 
    static void test1() {
        // do things
        checkWork(data);
    }
    @isTest 
    static void test2() {
        // do things
        checkWork(data);
    }
    static void checkWork(SObject data) {
        System.assertEquals(null, data.Id, 'this should be null');
    }
}

Expected outcome:

In the example given, PMD flags the checkWork function as it has a System.assert call within it. Yet actual test methods take no parameters. Flagging this function is unexpected as it is not a test method, and cannot be a test method as it accepts parameters. IMO the rule should be improved to exclude methods with parameters as these cannot be actual test methods.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
CLI and/or VSCode - same result


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