Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is assertThat() method?

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?

like image 371
Private Avatar asked Apr 30 '26 01:04

Private


1 Answers

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

like image 141
Ranjitha Murthy Avatar answered May 04 '26 08:05

Ranjitha Murthy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!