转载:http://blog.csdn.net/hdyrz/article/details/78398964

测试类如下:

  1. package com.mmnn.test.testcase;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. public class Demo1Test
  5. {
  6. @Test
  7. public void TestMth1() {
  8. assertTrue("msg : mth1 test test test test", true);
  9. }
  10. @Test
  11. public void TestMth2() {
  12. assertTrue("msg : mth2 test test test test", true);
  13. }
  14. }
 
  1. package com.mmnn.test.testcase;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. public class Demo2Test
  5. {
  6. @Test
  7. public void TestMth3() {
  8. assertTrue("msg : mth3 test test test test", true);
  9. }
  10. @Test
  11. public void TestMth4() {
  12. assertTrue("msg : mth4 test test test test", false);
  13. }
  14. }
  1. export JAVA_HOME=/opt/tools/jdk1.7.0_17
  2. cd /path/to/testproject/whichhasPomFile
  3. /opt/tools/apache-maven-3.1.1/bin/mvn -s /opt/tools/apache-maven-3.1.1/conf/settings.xml clean -Dtest=TestCal test

一、使用maven-surefire-plugin插件自带report功能

注意:

1、单独运行mvn test,默认执行的就是maven-surefire-plugin

2、配置了maven-surefire-plugin后,运行mvn test,结果和1一致,生成xml、txt文件

3、运行mvn test surefire-report:report 即是:运行mvn test的基础上,根据生成的xml、txt文件,再生成默认格式的report

  1. mvn -s C:\maven\conf\settings.xml clean -Dtest=TestClass surefire-report:report test
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.mmnn.test</groupId>
  5. <artifactId>mvnjunit1</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <properties>
  8. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9. </properties>
  10. <build>
  11. <plugins>
  12. <plugin>
  13. <groupId>org.apache.maven.plugins</groupId>
  14. <artifactId>maven-compiler-plugin</artifactId>
  15. <version>2.0.2</version>
  16. <configuration>
  17. <source>1.8</source>        <!-- //////////// -->
  18. <target>1.8</target>
  19. </configuration>
  20. </plugin>
  21. <plugin>
  22. <artifactId>maven-surefire-plugin</artifactId>
  23. <configuration>
  24. <testFailureIgnore>true</testFailureIgnore> <!-- //////////// -->
  25. <includes>
  26. <include>**/*Test.java</include>    <!-- //////////// -->
  27. </includes>
  28. <excludes>
  29. <!-- -->
  30. </excludes>
  31. </configuration>
  32. </plugin>
  33. </plugins>
  34. </build>
  35. <dependencies>
  36. <dependency>
  37. <groupId>junit</groupId>
  38. <artifactId>junit</artifactId>
  39. <version>4.5</version>
  40. <scope>test</scope>
  41. </dependency>
  42. </dependencies>
  43. </project>

运行 mvn test surefire-report:report 即可:

二、使用maven-antrun-extended-plugin

使用maven-surefire-plugin生成的报告太丑,可以通过maven-antrun系列插件生成更友好的报告:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.mmnn.test</groupId>
  5. <artifactId>mvnjunit2</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <properties>
  8. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9. </properties>
  10. <build>
  11. <plugins>
  12. <plugin>
  13. <groupId>org.apache.maven.plugins</groupId>
  14. <artifactId>maven-compiler-plugin</artifactId>
  15. <version>2.0.2</version>
  16. <configuration>
  17. <source>1.8</source>
  18. <target>1.8</target>
  19. </configuration>
  20. </plugin>
  21. <!-- mvn test生成xml txt测试报告(命令行不带surefire-report:report时) -->
  22. <plugin>
  23. <artifactId>maven-surefire-plugin</artifactId>
  24. <configuration>
  25. <testFailureIgnore>true</testFailureIgnore> <!-- //////////// -->
  26. <includes>
  27. <include>**/*Test.java</include>    <!-- //////////// -->
  28. </includes>
  29. <excludes>
  30. <!-- -->
  31. </excludes>
  32. </configuration>
  33. </plugin>
  34. <!-- 用mvn ant生成格式更友好的report -->
  35. <plugin>
  36. <groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
  37. <artifactId>maven-antrun-extended-plugin</artifactId>   <!-- //////////// -->
  38. <executions>
  39. <execution>
  40. <id>test-reports</id>
  41. <phase>test</phase> <!-- //////////// -->
  42. <configuration>
  43. <tasks>
  44. <junitreport todir="${basedir}/target/surefire-reports">
  45. <fileset dir="${basedir}/target/surefire-reports">
  46. <include name="**/*.xml" />
  47. </fileset>
  48. <report format="frames" todir="${basedir}/target/surefire-reports" /> <!-- //////////// -->
  49. </junitreport>
  50. </tasks>
  51. </configuration>
  52. <goals>
  53. <goal>run</goal>
  54. </goals>
  55. </execution>
  56. </executions>
  57. <dependencies>
  58. <dependency>
  59. <groupId>org.apache.ant</groupId>
  60. <artifactId>ant-junit</artifactId>
  61. <version>1.8.0</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>org.apache.ant</groupId>
  65. <artifactId>ant-trax</artifactId>
  66. <version>1.8.0</version>
  67. </dependency>
  68. </dependencies>
  69. </plugin>
  70. </plugins>
  71. </build>
  72. <dependencies>
  73. <dependency>
  74. <groupId>junit</groupId>
  75. <artifactId>junit</artifactId>
  76. <version>4.5</version>
  77. <scope>test</scope>
  78. </dependency>
  79. </dependencies>
  80. </project>

运行mvn test:


maven运行junit用例并生成报告maven-surefire-plugin,maven-antrun-extended-plugin的更多相关文章

  1. maven运行junit用例并生成报告

    原文地址https://blog.csdn.net/hdyrz/article/details/78398964 测试类如下: [java] view plain copypackage com.mm ...

  2. Maven运行JUnit测试(http://www.360doc.com/content/13/0927/15/7304817_317455642.shtml)

    Maven单元测试 分类: maven 2012-05-09 15:17 1986人阅读 评论(1) 收藏 举报 maven测试junit单元测试javarandom   目录(?)[-] maven ...

  3. Jmeter 运行结果的csv文件生成报告

    把运行结果保存到本地,下次可以直接用结果生成测试报告. 一.首先保证脚本能正常运行 二.本地创建csv文件,用来保存运行结果 三.察看结果树,选择本地文件(上一步创建好的csv文件),保存运行结果,如 ...

  4. 执行用例,并生成报告——discover,HTMLRunner

    HTMLRunner需要下载Python3的格式,懒人链接:http://pan.baidu.com/s/1tp3Ts 参考:http://bbs.chinaunix.net/thread-41547 ...

  5. 9-Unittest+HTMLTestRunner不能生成报告解决方法

    1.问题现象 在使用HTMLTestRunner生成测试报告时,出现程序运行不报错,但不能生成报告的情况. 刚开始找了很久没发现问题,后来加上打印信息,发现根本没执行生成报告这部分代码.最后网上找到原 ...

  6. jmeter学习记录--09--命令行运行与生成报告

    一.     使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...

  7. day11_单元测试_读取yaml文件中的用例,自动获取多个yaml文件内容执行生成报告

    一.使用.yaml格式的文件直接可以存放字典类型数据,如下图,其中如果有-下一行有缩进代表这是个list,截图中是整体是一个list,其中有两部分,第二部分又包含另外一个list 二.单元测试:开发自 ...

  8. jmeter命令行运行与生成报告

    一.     使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...

  9. unittest自动化测试举例:自动读取ymal用例&调用接口并生成报告

    用unittest框架写的接口自动化实现过程: 1.编写ymal格式用例: 2.导入ddt模块,该模块的主要功能是帮你读取ymal用例文件,自动获取内容并循环调用函数,具体见代码. 3.导入Beaut ...

随机推荐

  1. k8s的Rolling Update(滚动更新应用)

    滚动更新是一次只更新一小部分副本,成功后,再更新更多的副本,最终完成所有副本的更新.滚动更新的最大的好处是零停机,整个更新过程始终有副本在运行,从而保证了业务的连续性. 下面我们部署三副本应用: 初始 ...

  2. 《锋利的jQuery》读书要点笔记6——制作商城网页:结构和样式设计

    第8章 用jQuery打造个性网站 做一个购物网站并用jQuery来完善.大体步骤是: 收集素材 确定网站结构 A. 文件结构,imagea文件夹用来存放将要用到的图片,styles文件夹存放CSS, ...

  3. deepin使用root身份运行

    https://blog.csdn.net/guanripeng/article/details/79630619

  4. (七)MySQL数据操作DQL:多表查询2

    (1)准备环境 1)创建员工表 mysql> create table company.employee6( -> emp_id int auto_increment primary ke ...

  5. C# 用程序读写另一个控制台程序

    一. using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.W ...

  6. 奶牛与农夫John与oj

    当蒟蒻的我悲惨的发现oj出现大量的奶牛与农夫时,觉得早晚usaco要占领oj,于是绝望的开始记录农夫与奶牛的题目……. 一道usaco月赛的题…在oj用作练习二维数组,虽然数据的大量字符确实很让人不爽 ...

  7. linux查看进程内存占用

    ps -aux | grep xxx USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND 可以看到RSS ...

  8. Compare, sort, and delete duplicate lines in Notepad ++

    Compare, sort, and delete duplicate lines in Notepad ++ Organize Lines: Since version 6.5.2 the app ...

  9. centos7下ip转发的配置

    1.先确认ipv4配置了转发设置 vim /etc/sysctl.conf                    #命令1(编辑配置文件) net.ipv4.ip_forward=1          ...

  10. 【DFS序】【线段树】bzoj4034 [HAOI2015]T2

    分开维护树的入栈序和出栈序,用两棵线段树.回答时就是用一颗的减去另一棵的. #include<cstdio> #include<algorithm> using namespa ...