You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
do we have an equality check method for random generated beans? #272
hi, today I was writing some unit tests and found random-beans, I think it's cool and make my life so much easier. I can generate random beans for test data-preparation which have a lot of fields.
for example:
@AutowiredprivatePersonDaodao;
@TestpublicvoidsaveTest() {
Personperson = enhancedRandom.nextObject(Person.class);
dao.insertSelective(person);
PersonpersonEntity = dao.selectByPrimaryKey(person.getId());
// test whether person has the same fields as personEntity
}
The problem is I don't know how to easily check fileds equality between generated bean and the selected entity bean using DAO.
So, Is there an equality check method for random generated beans?
Thanks. isEqualsToByComparingFields really does what I want. The cost is to import another library.
I suppose I shoud reinvent some code for equality check only, maybe an another Utils.java, which can be small and handful.
AssertJ has really read-able and easy to use DSL (https://joel-costigliola.github.io/assertj/), great support for specific assertions on JDK types (String, Iterable, Streams, etc.) and very helpful error messages.
It also has not dependencies, so it's only single additional dependency.
You should give it try. It's the best java assertion library imho.
Activity
fmbenhassine commentedon Sep 22, 2017
Hi,
Thank you, I'm glad you find random beans useful!
If you are using assertj, you can use the
isEqualsToByComparingFieldsmethod. For example:This will compare all fields for you. Does this help?
Kr
Mahmoud
fyh commentedon Sep 26, 2017
Hi,
Thanks.
isEqualsToByComparingFieldsreally does what I want. The cost is to import another library.I suppose I shoud reinvent some code for equality check only, maybe an another
Utils.java, which can be small and handful.PascalSchumacher commentedon Sep 26, 2017
AssertJ has really read-able and easy to use DSL (https://joel-costigliola.github.io/assertj/), great support for specific assertions on JDK types (String, Iterable, Streams, etc.) and very helpful error messages.
It also has not dependencies, so it's only single additional dependency.
You should give it try. It's the best java assertion library imho.
fmbenhassine commentedon Sep 26, 2017
Don't reinvent the wheel 😄 Seriously, use assertj, it's super awesome.