import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; public class ExampleTest { @Test public void testAddition() { int result = Calculator.add(2, 2); assertThat(result).isEqualTo(4); } @Test public void testAdditionWithMessage() { int result = Calculator.add(3, 3); assertWithMessage("Addition not working correctly").that(result).isEqualTo(6); } } Expected: 6 But was: 5 import static com.google.common.truth.Truth8.assertThat; public class ExampleTest { @Test public void testStringLength() { String str = "Hello World"; assertThat(str).hasLength(11); } } <dependency> <groupId>com.google.truth</groupId> <artifactId>truth</artifactId> <version>1.0</version> <scope>test</scope> </dependency> groovy testCompile 'com.google.truth:truth:1.0'


上一篇:
下一篇:
切换中文