Comparing only fields does not work with List Of Objects. It is passed without error, although mismatch is present.
- assertj core version: 3.24.2
- java version: Java 1.8
- test framework version: TestNG 7.4.0
- os (if relevant): NA
//sample class
public class Student {
String name;
String subject;
int rollNo;
public Student(String name, String subject, int rollNo) {
this.name = name;
this.subject = subject;
this.rollNo = rollNo;
}
}
Add a test case showing the bug that we can run
//Test class
public class AssertTest {
@Test
public void ComparingByFields(){
List<Student> actual = new ArrayList<>();
actual.add(new Student("John", "math", 1));
actual.add(new Student("Rohit", "english", 2));
List<Student> expected = new ArrayList<>();
expected.add(new Student("Jon", "math", 1));
expected.add(new Student("Rohit", "english", 2);
assertThat(actual)
.usingRecursiveComparison()
.comparingOnlyFields( "name", "subject")
.isEqualTo(expected);
}
}
It should throw an error on 'name' property because of mismatch on first object.
Comparing only fields does not work with List Of Objects. It is passed without error, although mismatch is present.
//sample class
public class Student {
String name;
String subject;
int rollNo;
}
Add a test case showing the bug that we can run
//Test class
public class AssertTest {
}
It should throw an error on 'name' property because of mismatch on first object.