自动化测试框架
组织测试的结构
组织测试的结构最核心的就是测试用例如何写,以及合理使用setUp 和 tearDown 函数来减少重复代码和及时释放资源。
断言
而断言则是保证了我们测试
的目标。断言程序库有很多,你可以根据自己的喜好进行选择。除了断言程序库,Mock
框架的 verify 也是一种断言。
常用断言库
Hamcrest
assertThat(calculator.subtract(4, 1), is(equalTo(3)));
AssertJ
assertThat(frodo.getName()).startsWith("Fro")
.endsWith("do")
.isEqualToIgnoringCase("frodo");
Truth
assertThat(projectsByTeam())
.valuesForKey("corelibs")
.containsExactly("guava", "dagger", "truth", "auto", "caliper");
Junit5
Assertions.assertThrows(IllegalArgumentException.class, () -> {
Integer.parseInt("One");
});