标签:
------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.cn.qin.actionTest.UserActionTest sdffsdfsdf Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.061 sec - in com.cn.qin.actionTest.UserActionTest Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] <<< cobertura-maven-plugin:2.5.1:cobertura (cobertura-report) < [cobertura]test @ Struts <<< [INFO] [INFO] --- cobertura-maven-plugin:2.5.1:cobertura (cobertura-report) @ Struts --- [INFO] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Cobertura: Loaded information on 3 classes. Report time: 298ms
运行报告是junit自己的报告输出,和咱们在Eclipse运行的报告差不多。以上代表运行了3个用例,和预期效果不符的是0个,失败的用例是0个,忽略的用例数是0个。 如果需要跳过单元测试,则可以运行如下命令
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
等到项目完全开发完了,需要测试用例的时候将其注释掉即可。
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> <configuration> <includes> <include>**/*Test.java</include> </includes> <excludes> <exclude>**/AccountImageUtilTest.java</exclude> </excludes> </configuration> </plugin> </plugins> </build>
其中includes是需要测试的类,excludes是要排除之外测试用例。可以使用模糊匹配。**用来匹配任意件路经,*匹配任意类。
Junit的单元测试报告的pom.xml配置
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.12.2</version> <configuration> <showSuccess>false</showSuccess> </configuration> </plugin> </plugins> </build>
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> </plugin> </plugins> </build>
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <!--设置包含的测试类 --> <includes> <include>******</include> <include>*/User*</include> </includes> <!-- 设置不进行测试类 --> <excludes> <exclude>Test*</exclude> </excludes> <!-- 跳过测试阶段,測試類写的有问题也会出错,一般不推荐 --> <!--<skip>true</skip> --> </configuration> </plugin> <!-- 构建项目站点报告插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.0-beta-3</version> <configuration> <!-- 配置站点国际化 --> <locales>zh_CN</locales> <!-- 输出编码 --> <outputEncoding>GBK</outputEncoding> </configuration> </plugin> <!-- 项目API doc报告 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> </plugin> <!-- 单元测试报告html --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.12.2</version> <configuration> <showSuccess>false</showSuccess> </configuration> </plugin> <!-- 测试覆盖率的报告 --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> </configuration> <executions> <execution> <id>cobertura-report</id> <goals> <goal>cobertura</goal> </goals> <phase>test</phase> </execution> </executions> </plugin> </plugins> </build>
生成的测试覆盖率会在你自己项目的target/site/cobertura/下面 我的路径是 file:///D:/InstallSoft/V2/workspace/user-parent/Struts/target/site/cobertura/index.html
标签:
原文地址:http://www.cnblogs.com/qinpengming/p/5225380.html