原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
1. 在Maven中配置测试插件surefire
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- </plugin>
2. 默认被执行的测试 默认情况下,surefire会执行文件名以Test开头或结尾的测试用例,或者是以TestCase结尾的测试用例。
- "**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test".
- "**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test".
- "**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase".</span>
3. 跳过测试 Skipping Tests
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- <span style="color:#009900;"> <configuration>
- <skipTests>true</skipTests>
- </configuration></span>
- </plugin>
- </plugins>
- </build>
- 补充:如果使用Junit或者TestNG也可以直接在当前测试方法上加注解@Ignore忽略,这是加了该注解的也都会被skip
4. 排除测试 Exclusions (Junit & TestNG 通用)
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- <configuration>
- <span style="color:#009900;"> <excludes>
- <exclude>**/TestCircle.java</exclude>
- <exclude>**/TestSquare.java</exclude>
- </excludes></span>
- </configuration>
- </plugin>
- </plugins>
- </build>
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
mvn -Dtest=TestCi*le test *表示任何
mvn -Dtest=TestSquare,TestCi*le test 如果测试类没有使用规范的命名,可以显示的直接指定测试方法的名称
- Running a set of methods in a Single Test Class
- With version 2.7.3, you can run only n tests in a single Test Class.
- NOTE : it's supported for junit 4.x and TestNG.
- You must use the following syntax
- mvn -Dtest=TestCircle#mytest test
- You can use patterns too
- mvn -Dtest=TestCircle#test* test
- As of surefire 2.12.1, you can select multiple methods (JUnit4X only at this time, patches welcome)
- mvn -Dtest=TestCircle#testOne+testTwo test
6. 如何使用TestNG
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>6.3.1</version>
- <scope>test</scope>
- </dependency>
- If using an older version of TestNG (<= 5.11)
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>5.11</version>
- <scope>test</scope>
- <span style="color:#009900;"> <classifier>jdk15</classifier></span>
- </dependency>
默认会执行的测试用例:*Test.java
7. 如何使用TestNG的 suite
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- <configuration>
- <span style="color:#009900;"><suiteXmlFiles>
- <suiteXmlFile>testng.xml</suiteXmlFile>
- </suiteXmlFiles></span>
- </configuration>
- </plugin>
注意:This configuration will override the includes and excludes patterns and run all tests in the suite files.
原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
8. 执行群组测试 execute one or more specific groups (Junit & TestNG 通用)
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- <configuration>
- <span style="color:#009900;"> <groups>functest,perftest</groups></span>
- </configuration>
- </plugin>
9. 多线程的运行测试用例 Running tests in parallel (Junit & TestNG 通用)
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- <configuration>
- <span style="color:#009900;"><parallel>methods</parallel>
- <threadCount>10</threadCount></span>
- </configuration>
- </plugin>
10. 如何使用Junit Using JUnit
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.1</version>
- <scope>test</scope>
- </dependency>
11. 如何使用Junit Category Using JUnit Categories
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.11</version>
- <configuration>
- <span style="color:#009900;"> <strong><groups>com.mycompany.SlowTests</groups></strong></span>
- </configuration>
- </plugin>
仅有带该注解的测试 或者 是当前注解 类/接口的 子类 会被执行,
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/interfaceSlowerTests
is subclass ofSlowTests
:
- public interface SlowTests{}
- public interface SlowerTests extends SlowTests{}
- ------------------------------------------------------------------------------------------------
- ic class AppTest {
- @Test
- @Category(com.mycompany.SlowTests.class)
- public void testSlow() {
- System.out.println("slow");
- }
- @Test
- @Category(com.mycompany.SlowerTests.class)
- public void testSlower() {
- System.out.println("slower");
- }
- @Test
- @Category(com.cmycompany.FastTests.class)
- public void testSlow() {
- System.out.println("fast");
- }
- }
参考:
Junit的@Category详解
12. 如何debug TestCases
- mvnDebug -DforkCount=0 test dubug非fork的测试
- 在debug的需求时,还是使用Eclipse最方便
13. 使用系统属性 Using System Properties
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- <configuration>
- <span style="color:#009900;"><systemPropertyVariables>
- <propertyName>propertyValue</propertyName>
- <buildDirectory>${project.build.directory}</buildDirectory>
- [...]
- </systemPropertyVariables></span>
- </configuration>
- </plugin>
- </plugins>
- </build>
14. 选择surefire provider
surefire 默认会根据工程的classpath中已有的Junit|TestNG的版本来选择 test-framework provider,我们也可以手动的选择和覆盖当前的provider
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.surefire</groupId>
- <span style="color:#009900;"> <artifactId>surefire-junit47</artifactId></span>
- <version>2.17</version>
- </dependency>
- </dependencies>
- </plugin>
目前已经提供的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
原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
相关推荐
在Maven中配置测试插件surefire2.默认被执行的测试 默认情况下,surefire会执行文件名以Test开头或结尾的测试用例,或者是以TestCase结尾的测试用例。 3.跳过测试SkippingTests4.排除测试Exclusions(Junit&TestNG ...
maven-surefire-plugin-2.22.1.jar
maven-surefire-plugin 2.12
maven-surefire-plugin-2.7.1.jar
idea中maven项目右侧插件红线,可能需要手动导入架包等文件,直接把压缩包考进去就行。我的F:\maven_repository\org\apache\maven\plugins\maven-surefire-plugin文件夹下
4、在links中新建maven.txt文件,内容为插件地址,例如:path=D:\eclipse_gzds\myplugins\maven(注意这里斜杠,不是反斜杠) 5、将maven.txt扩展名改为maven.lin 6、在eclipse根目录下找到eclipse.ini并打开,在...
maven开发必须插件,便于后期maven开发同时配置文件已经配置好,可以直接使用。
Maven使用tomcat8-maven-plugin插件
eclipse maven plugin 插件 安装 和 配置
Maven_pom.xml常用配置解析
Maven的配置及使用,Maven的配置及使用Maven的配置及使用Maven的配置及使用Maven的配置及使用Maven的配置及使用Maven的配置及使用
Eclipse中Maven插件Eclipse中Maven插件Eclipse中Maven插件Eclipse中Maven插件
maven常用命令以及以个测试项目方便测试
Maven用于配置管理工程所需的jar包,所有工程统一应用Maven配置的jar。这样方便工程的管理,不需要每次替换jar包文件,只需要...包括maven3.0.3工具、eclipse的maven插件、相关的配置说明、本地配置的setings.xml文件。
maven-surefire-plugin-2.4.2.jar
maven中setting阿里云的详细镜像配置,setting的配置细节 maven中setting阿里云的详细镜像配置,setting的配置细节
对于eclipse无法在线安装maven插件的解决办法。首先windows配置maven环境,然后在eclipse离线安装maven插件。具体方法可以在我的博客中看到
Maven配置文件Maven配置文件
创建Maven项目所需的插件,及打包Maven项目(源码包,全量包)的pom文件,下载Tomcat的pom文件
maven仓库基本插件 maven仓库基本插件 maven仓库基本插件 maven仓库基本插件