Affects PMD Version: 6.5.0-SNAPSHOT
Rule: JUnitTestContainsTooManyAsserts
Description:
The Analysis seems to detect more than one assertTrue
s 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
ArnaudLec and christianhujer
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