0

I want to know what could be the better way to use

assertEquals()

between two objects without defining

equals()

method.

I wanted to use the org.apache.commons.lang3.builder.EqualsBuilder : Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,actual));

But i read in the documentation that it is not the best way to compare two objects : COMMONS Doc.

Also I would like to find an open source library that can do that or even better : no library.

Thank you.

niryo
  • 31
  • 3
  • 1
    Possible duplicate of [How do I assert equality on two classes without an equals method?](http://stackoverflow.com/questions/12147297/how-do-i-assert-equality-on-two-classes-without-an-equals-method) – Stefan Birkner Apr 07 '17 at 11:46

3 Answers3

0

I think that the advice regarding problems with the SecurityManager does not apply to your test code because you have control over the environment where your tests are running.

Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
-1

I believe you can use something like:

assertThat(Object1, is(Object2));

Using Hamcrest.

-1

You could auto generate equals if this is an option for you using Lombok project: https://projectlombok.org/features/EqualsAndHashCode.html

LLL
  • 1,777
  • 1
  • 15
  • 31