Regarding JUnit4 assertThat
, I have seen this done both ways. Is one correct over the other or is it all the same?
byte[] val;
...
assertThat(val, notNullValue());
--vs--
assertThat(val, is(notNullValue()));
The second option reads "assert that val is not null" which sounds better. (On the other hand, it may be redundant.)
I have used both ways and they seem to produce correct results.
The Hamcrest documentation says:
Hamcrest strives to make your tests as readable as possible. For example, the
is
matcher is a wrapper that doesn't add any extra behavior to the underlying matcher. The following assertions are all equivalent:assertThat(theBiscuit, equalTo(myBiscuit)); assertThat(theBiscuit, is(equalTo(myBiscuit))); assertThat(theBiscuit, is(myBiscuit));
The last form is allowed since
is(T value)
is overloaded to returnis(equalTo(value))
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With