나는 꽤 많은 수의 클래스가 Serializable
/Externalizable
이고 불행히도 클래스에 추가 할 때 새로운 필드를 serailize/desirialize하거나 readDouble
대신에 readObject
을 잘못 입력하는 것을 잊어 버린다. 그래서 무시되고 실행되지 않는 단위 테스트를 작성하기로했습니다. maven-surefire-plugin
. 그것은 내 자신을위한 것입니다.두 개체를 필드로 비교하는 방법은 무엇입니까?
@Test(enabled = false)
public void testEquality(Object o){
String oPart = o.toString();
try (FileOutputStream fos = new FileOutputStream("/home/myusr/testser/" + oPart);
ObjectOutputStream ous = new ObjectOutputStream(fos)) {
ous.writeObject(o);
} catch (FileNotFoundException | IOException e) {
e.printStackTrace();
}
Object oo = null;
try (FileInputStream fis = new FileInputStream("/home/myusr/testser/" + oPart);
ObjectInputStream ois = new ObjectInputStream(fis)) {
Object oo = ois.readObject();
} catch (FileNotFoundException | IOException | ClassNotFoundException e) {
e.printStackTrace();
}
// Need to compare all non-transient fields of o and oo
}
을하지만 문제는 같은 이름을 가진 transient
아닌 모든 필드를 비교하는 방법이다 : 그것은 다음과 같습니다. 나는 테스트 목적으로 만 equals
메서드를 재정의하고 싶지 않습니다.
처리 방법이 있습니까? 어쩌면 그것에 대응할 수있는 commons
/guava
라이브러리가있을 수 있습니다.
[shazamcrest] (https://github.com/shazam/shazamcrest)를 보았습니까? –