原文地址https://blog.csdn.net/hdyrz/article/details/78398964

测试类如下:

[java] view plain copy
package com.mmnn.test.testcase;  
  
import static org.junit.Assert.assertTrue;  
  
import org.junit.Test;  
  
public class Demo1Test   
{  
    @Test  
    public void TestMth1() {  
        assertTrue("msg : mth1 test test test test", true);  
    }  
      
    @Test  
    public void TestMth2() {  
        assertTrue("msg : mth2 test test test test", true);  
    }  
}

[java] view plain copy
package com.mmnn.test.testcase;  
  
import static org.junit.Assert.assertTrue;  
  
import org.junit.Test;  
  
public class Demo2Test   
{  
    @Test  
    public void TestMth3() {  
        assertTrue("msg : mth3 test test test test", true);  
    }  
      
    @Test  
    public void TestMth4() {  
        assertTrue("msg : mth4 test test test test", false);  
    }  
}  
[plain] view plain copy
export JAVA_HOME=/opt/tools/jdk1.7.0_17  
  
cd /path/to/testproject/whichhasPomFile  
  
/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

[plain] view plain copy
mvn -s C:\maven\conf\settings.xml clean -Dtest=TestClass surefire-report:report test  
[html] view plain copy
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
    <modelVersion>4.0.0</modelVersion>  
    <groupId>com.mmnn.test</groupId>  
    <artifactId>mvnjunit1</artifactId>  
    <version>0.0.1-SNAPSHOT</version>  
  
    <properties>  
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    </properties>  
  
    <build>  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <version>2.0.2</version>  
                <configuration>  
                    <source>1.8</source>        <!-- //////////// -->  
                    <target>1.8</target>  
                </configuration>  
            </plugin>  
            <plugin>  
                <artifactId>maven-surefire-plugin</artifactId>  
                <configuration>  
                    <testFailureIgnore>true</testFailureIgnore> <!-- //////////// -->  
                    <includes>  
                        <include>**/*Test.java</include>    <!-- //////////// -->  
                    </includes>  
                    <excludes>  
                        <!-- -->  
                    </excludes>  
                </configuration>  
            </plugin>  
        </plugins>  
    </build>  
  
    <dependencies>  
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
            <version>4.5</version>  
            <scope>test</scope>  
        </dependency>  
    </dependencies>  
  
</project>

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

二、使用maven-antrun-extended-plugin

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

[html] view plain copy
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
    <modelVersion>4.0.0</modelVersion>  
    <groupId>com.mmnn.test</groupId>  
    <artifactId>mvnjunit2</artifactId>  
    <version>0.0.1-SNAPSHOT</version>  
  
    <properties>  
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    </properties>  
  
    <build>  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <version>2.0.2</version>  
                <configuration>  
                    <source>1.8</source>  
                    <target>1.8</target>  
                </configuration>  
            </plugin>  
  
            <!-- mvn test生成xml txt测试报告(命令行不带surefire-report:report时) -->  
            <plugin>  
                <artifactId>maven-surefire-plugin</artifactId>  
                <configuration>  
                    <testFailureIgnore>true</testFailureIgnore> <!-- //////////// -->  
                    <includes>  
                        <include>**/*Test.java</include>    <!-- //////////// -->  
                    </includes>  
                    <excludes>  
                        <!-- -->  
                    </excludes>  
                </configuration>  
            </plugin>  
  
            <!-- 用mvn ant生成格式更友好的report -->  
            <plugin>  
                <groupId>org.jvnet.maven-antrun-extended-plugin</groupId>  
                <artifactId>maven-antrun-extended-plugin</artifactId>   <!-- //////////// -->  
                <executions>  
                    <execution>  
                        <id>test-reports</id>  
                        <phase>test</phase> <!-- //////////// -->  
                        <configuration>  
                            <tasks>  
                                <junitreport todir="${basedir}/target/surefire-reports">  
                                    <fileset dir="${basedir}/target/surefire-reports">  
                                        <include name="**/*.xml" />  
                                    </fileset>  
                                    <report format="frames" todir="${basedir}/target/surefire-reports" /> <!-- //////////// -->  
                                </junitreport>  
                            </tasks>  
                        </configuration>  
                        <goals>  
                            <goal>run</goal>  
                        </goals>  
                    </execution>  
                </executions>  
                <dependencies>  
                    <dependency>  
                        <groupId>org.apache.ant</groupId>  
                        <artifactId>ant-junit</artifactId>  
                        <version>1.8.0</version>  
                    </dependency>  
                    <dependency>  
                        <groupId>org.apache.ant</groupId>  
                        <artifactId>ant-trax</artifactId>  
                        <version>1.8.0</version>  
                    </dependency>  
                </dependencies>  
            </plugin>  
        </plugins>  
    </build>  
  
  
    <dependencies>  
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
            <version>4.5</version>  
            <scope>test</scope>  
        </dependency>  
    </dependencies>  
  
</project>  
运行mvn test:

maven运行junit用例并生成报告的更多相关文章

  1. maven运行junit用例并生成报告maven-surefire-plugin,maven-antrun-extended-plugin

    转载:http://blog.csdn.net/hdyrz/article/details/78398964 测试类如下: package com.mmnn.test.testcase; import ...

  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. 在VS中安装/使用 MVVMLight

    一般来说,我喜欢使用NuGet来获取这些东西,比如Newtonsoft.Json.netlog4.MVVMLight 之类的东西.至于NuGet的使用,以后再说吧.为了直接进入正题,我们这里直接使用V ...

  2. C# GetType和typeof的区别

    typeof: The typeof operator is used to obtain the System.Type object for a type. 运算符,获得某一类型的 System. ...

  3. easyui-textbox 只读设置取消

    <script> $(function () { $("#txt_beginAmount").attr('readonly', true); $("#txt_ ...

  4. object - c 语言基础 进阶笔记 随笔笔记

    重点知识Engadget(瘾科技)StackOverFlow(栈溢出)Code4Apprespon魏先宇的程序人生第一周快捷键: Alt+上方向键 跳到最上面  Alt+下方向键 跳到最下面      ...

  5. Android Timer的应用示例

    package com.hyzhou.timerdemo1; import java.util.Timer; import java.util.TimerTask; import android.os ...

  6. java三方---->html解析jsoup的使用

    jsoup 是一款 Java 的HTML 解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于JQuery的操作方法来取出和操作数据.今天我 ...

  7. 深入浅出Docker(四):Docker的集成测试部署之道

    1. 背景 敏捷开发已经流行了很长时间,如今有越来越多的企业开始践行敏捷开发所提倡的以人为中心.迭代.循序渐进的开发理念.在这样的场景下引入Docker技术,首要目的就是使用Docker提供的虚拟化方 ...

  8. 小程序 - API 踩坑记录(更新中...)

    API 小程序API结构导览图: 声明: 请尊重博客园原创精神,转载或使用图片请注明: 博主:xing.org1^ 出处:http://www.cnblogs.com/padding1015/

  9. Ubuntu16.04安装Elasticsearch

    一.安装工作 wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - sudo apt-g ...

  10. C /C ++中结构体的定义

    c语言中结构体的定义: struct 结构体名{ 成员列表: ..... }结构体变量: 7.1.1 结构体类型变量的定义结构体类型变量的定义与其它类型的变量的定义是一样的,但由于结构体类型需要针对问 ...