What is assertThat() method? How can it be useful?
I had seen this method in mapreduce program in hadoop. Can anyone explain brief about it?
The assertThat() belongs to the Matchers class of Hamcrest. This method does similar functionality as that of assertEquals() of the Assert class, but assertThat() is more human readable.
For example:
assertEquals(BigDecimal.valueOf(1.8).setScale(2, RoundingMode.HALF_UP), actual);
assertThat(actual, is(equalTo(BigDecimal.valueOf(1.8).setScale(2, RoundingMode.HALF_UP))));
You can see that assertThat() is more of an English sentence and easy to understand. The above sentence asserts that if the actual value is equal to the expected value given.
You can find some examples on https://www.kloia.com/blog/better-unit-testing-with-hamcrest
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