断言两个java bean是等效的 [英] Assert that two java beans are equivalent

查看:101
本文介绍了断言两个java bean是等效的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很接近,但仍然不是我想要的.我想以一种通用的方式断言两个bean对象是等效的.如果它们不是,我想要一条详细的错误消息来说明差异,而不是布尔值等于"或不等于".

This question is close, but still not what I want. I'd like to assert in a generic way that two bean objects are equivalent. In case they are not, I'd like a detailed error message explaining the difference instead of a boolean "equal" or "not equal".

推荐答案

我建议您使用 unitils 库:

http://www.unitils.org/tutorial-reflectionassert.html


public class User {

    private long id;
    private String first;
    private String last;

    public User(long id, String first, String last) {
        this.id = id;
        this.first = first;
        this.last = last;
    }
}


User user1 = new User(1, "John", "Doe");
User user2 = new User(1, "John", "Doe");
assertReflectionEquals(user1, user2);

另请参阅:

  • Is there a Java reflection utility to do a deep comparison of two objects?
  • NUnit - Assert to check all properties are equal?

这篇关于断言两个java bean是等效的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆