JUnit 测试全解析:从基础到高级优化
1. 测试用例类命名规范
为了便于文件集的包含和排除辅助类或基础测试用例类,需要对测试用例类的命名方案进行标准化。通常的命名约定是,只有测试用例类以 “Test” 结尾。例如, HtmlDocumentTest 是测试用例,而 DocumentTestCase 是抽象基类,抽象测试用例类以 “TestCase” 作为后缀。
<junit printsummary="true" haltonfailure="true">
<classpath refid="test.classpath"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.data.dir}">
<fileset dir="${test.dir}" includes="**/*Test.class"/>
</batchtest>
</junit>
上述代码中的 includes 子句确保只考虑具体的测试用例类,而不包括抽象的 DocumentTestCase 类。将非 JUnit 类或抽象类传递给 <junit> 会导致错误。
超级会员免费看
订阅专栏 解锁全文
1044

被折叠的 条评论
为什么被折叠?



