原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
1. 在Maven中配置测试插件surefire
2. 默认被执行的测试 默认情况下,surefire会执行文件名以Test开头或结尾的测试用例,或者是以TestCase结尾的测试用例。
3. 跳过测试 Skipping Tests
4. 排除测试 Exclusions (Junit & TestNG 通用)
5. 仅执行一个/一类测试(repeat) Running a Single Test (Junit & TestNG 通用)
mvn -Dtest=TestCircle test test表示当前测试方法所在的测试类,不需要扩展名 The value for the test parameter is the name of the test class
test
mvn -Dtest=TestCi*le test *表示任何
mvn -Dtest=TestSquare,TestCi*le test 如果测试类没有使用规范的命名,可以显示的直接指定测试方法的名称
6. 如何使用TestNG
默认会执行的测试用例:*Test.java
7. 如何使用TestNG的 suite
注意:This configuration will override the includes and excludes patterns and run all tests in the suite files.
8. 执行群组测试 execute one or more specific groups (Junit & TestNG 通用)
9. 多线程的运行测试用例 Running tests in parallel (Junit & TestNG 通用)
10. 如何使用Junit Using JUnit
11. 如何使用Junit Category Using JUnit Categories
仅有带该注解的测试 或者 是当前注解 类/接口的 子类 会被执行,
This will execute only those tests annotated with the @Category(com.mycompany.SlowTests.class) annotation and those tests annotated with @Category(com.mycompany.SlowerTests.class) if class/interface SlowerTests is subclass of SlowTests:
@Category(com.mycompany.SlowTests.class)
@Category(com.mycompany.SlowerTests.class)
SlowerTests
SlowTests
参考:
Junit的@Category详解
12. 如何debug TestCases
13. 使用系统属性 Using System Properties
14. 选择surefire provider
surefire 默认会根据工程的classpath中已有的Junit|TestNG的版本来选择 test-framework provider,我们也可以手动的选择和覆盖当前的provider
目前已经提供的provider有surefire-junit3, surefire-junit4, surefire-junit47 and surefire-testng
参考:http://mvnrepository.com/artifact/org.apache.maven.surefire
注意:选择手动指定provider时,不要忘记安装test framework
15. class Loading issues
please refer to:
http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html