Closed GoogleCodeExporter closed 8 years ago
You're misusing the assertThat method, really. It's not intended to be used to
test
the methods that it itself is calling. Rather, it assumes that they work and
are
being used to test something else.
A test for equals should call equals directly. E.g.
assertFalse(myObject.equals(null));
Original comment by nat.pr...@gmail.com
on 16 Oct 2007 at 5:13
I know what you're saying, but the difference in syntax is going to be a bit
subtle
for most people. I'm now aware of the problem and will (have to) write my test
code
differently, but most people won't realise that equalTo doesn't necessarily call
equals().
The other reason that this behaviour susprised me was that JUnit's
implementation of
assertEquals() doesn't contain the same optimisation as Hamcrest's equalTo()
method.
So when translating existing logic, there's a big gotcha.
The only reason I found the problem was that I did the Right Thing(tm) of
running my
tests [to ensure that they failed] before I fixed the problem.
Apart from the obvious (very tiny) performance benefit, is there a reason not to
change the behaviour of the Hamcrest equalTo matcher so that it's a) less
subtle and
b) closer to the behaviour of the existing JUnit logic?
Original comment by Royst...@gmail.com
on 22 Oct 2007 at 12:22
Fixed in trunk.
Original comment by joe.wal...@gmail.com
on 22 Oct 2007 at 7:12
Original issue reported on code.google.com by
Royst...@gmail.com
on 16 Oct 2007 at 3:51