assertThat()方法和assertEquals()方法都是JUnit框架中用于断言测试结果的方法,但它们之间有一些区别。
使用方式:
assertThat(actual, Matchers.is(expected));
assertThat(actual, Matchers.allOf(Matchers.greaterThan(0), Matchers.lessThan(100)));
assertEquals(expected, actual);
对比方式:
assertThat(actual, Matchers.is(expected));
assertThat(actual, Matchers.containsString("Hello"));
错误信息:
Expected: is "Hello"
but: was "World"
expected:<Hello> but was:<World>
总的来说,assertThat()方法更加灵活,可以进行更复杂的断言,而assertEquals()方法更加简单直观,适合进行简单的相等比较。