Skip to content

[apex] ApexAssertionsShouldIncludeMessage and ApexUnitTestClassShouldHaveAsserts: support new Assert class (introduced with Apex v56.0) #4096

@tprouvot

Description

@tprouvot

Affects PMD Version:
all

Rules:

Description:
With the Winter 23' release, a new class can be used to perform assertion in test class.
We have to add the new methods to existing rule to avoid false positive when this class will be used.

Apex class Assert
Code Sample demonstrating the issue:

@isTest
public with sharing class Test {

	@isTest
	public static void testAssert(){
		String sub = 'abcde'.substring(2);
		Assert.areEqual('cde', sub, 'Expected characters after first two');
	}
}

Expected outcome:

PMD reports a violation at line ..., but that's wrong. That's a false positive.
image

Running PMD through: [VS Code]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions