maven运行junit用例并生成报告mavensurefireplugin,mavenantrunextendedplugin 您所在的位置:网站首页 junit功能 maven运行junit用例并生成报告mavensurefireplugin,mavenantrunextendedplugin

maven运行junit用例并生成报告mavensurefireplugin,mavenantrunextendedplugin

2023-03-10 12:50| 来源: 网络整理| 查看: 265

转载:http://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  

 

注意:

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.0modelVersion>       groupId>com.mmnn.testgroupId>       artifactId>mvnjunit1artifactId>       version>0.0.1-SNAPSHOTversion>          properties>           project.build.sourceEncoding>UTF-8project.build.sourceEncoding>       properties>          build>           plugins>               plugin>                   groupId>org.apache.maven.pluginsgroupId>                   artifactId>maven-compiler-pluginartifactId>                   version>2.0.2version>                   configuration>                       source>1.8source>                               target>1.8target>                   configuration>               plugin>               plugin>                   artifactId>maven-surefire-pluginartifactId>                   configuration>                       testFailureIgnore>truetestFailureIgnore>                        includes>                           include>**/*Test.javainclude>                           includes>                       excludes>                                                  excludes>                   configuration>               plugin>           plugins>       build>          dependencies>           dependency>               groupId>junitgroupId>               artifactId>junitartifactId>               version>4.5version>               scope>testscope>           dependency>       dependencies>      project>  

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

 

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

 

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

 

二、使用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.0modelVersion>       groupId>com.mmnn.testgroupId>       artifactId>mvnjunit2artifactId>       version>0.0.1-SNAPSHOTversion>          properties>           project.build.sourceEncoding>UTF-8project.build.sourceEncoding>       properties>          build>           plugins>               plugin>                   groupId>org.apache.maven.pluginsgroupId>                   artifactId>maven-compiler-pluginartifactId>                   version>2.0.2version>                   configuration>                       source>1.8source>                       target>1.8target>                   configuration>               plugin>                                 plugin>                   artifactId>maven-surefire-pluginartifactId>                   configuration>                       testFailureIgnore>truetestFailureIgnore>                        includes>                           include>**/*Test.javainclude>                           includes>                       excludes>                                                  excludes>                   configuration>               plugin>                                 plugin>                   groupId>org.jvnet.maven-antrun-extended-plugingroupId>                   artifactId>maven-antrun-extended-pluginartifactId>                      executions>                       execution>                           id>test-reportsid>                           phase>testphase>                            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>rungoal>                           goals>                       execution>                   executions>                   dependencies>                       dependency>                           groupId>org.apache.antgroupId>                           artifactId>ant-junitartifactId>                           version>1.8.0version>                       dependency>                       dependency>                           groupId>org.apache.antgroupId>                           artifactId>ant-traxartifactId>                           version>1.8.0version>                       dependency>                   dependencies>               plugin>           plugins>       build>             dependencies>           dependency>               groupId>junitgroupId>               artifactId>junitartifactId>               version>4.5version>               scope>testscope>           dependency>       dependencies>      project>  

运行mvn test:

 

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

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



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有