Affects PMD Version: 6.5.0-SNAPSHOT
Rule: JUnitTestContainsTooManyAsserts
Description:
The Analysis seems to detect more than one assertTrues inside a JUnit 5 assertAll which represents a logical combination of assertions and thus one assertion. Such a setup should thus be treated as one assertion and JUnitTestContainsTooManyAsserts shouldn't be raised if no other assert[...] is present in the method.
Code Sample demonstrating the issue:
public class SomeClass {
public int someMethod(MutableInteger mutableInteger) {
mutableInteger.setValue(mutableInteger.getValue()+1);
return -1;
}
}
public class SomeClassTest {
@Test
public void testSomeMethod() {
MutableInteger mutableInteger = new MutableInteger(2);
SomeClass instance = new SomeClass();
int expResult = -1;
int result = instance.someMethod(mutableInteger);
assertAll(() -> assertEquals(expResult, result),
() -> assertEquals(3, mutableInteger.getValue()));
}
}
public class MutableInteger {
private int value;
public MutableInteger(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
See https://gitlab.com/krichter/pmd-asssert-all/ for project download and https://gitlab.com/krichter/pmd-asssert-all/-/jobs/77540065 for example CI output.
Running PMD through: Maven
Affects PMD Version: 6.5.0-SNAPSHOT
Rule: JUnitTestContainsTooManyAsserts
Description:
The Analysis seems to detect more than one
assertTrues inside a JUnit 5assertAllwhich represents a logical combination of assertions and thus one assertion. Such a setup should thus be treated as one assertion andJUnitTestContainsTooManyAssertsshouldn't be raised if no otherassert[...]is present in the method.Code Sample demonstrating the issue:
See https://gitlab.com/krichter/pmd-asssert-all/ for project download and https://gitlab.com/krichter/pmd-asssert-all/-/jobs/77540065 for example CI output.
Running PMD through: Maven