2010-05-17 127 views
27

我发现surefire-report插件非常不适合我的工作风格。我一直都在清理这个项目,每次我想在浏览器中查看测试报告时,我都不想花费5分钟来重建整个站点。Maven有没有像样的HTML Junit报告插件?

如果我输入mvn surefire-report:report-only,生成的报告太丑陋,几乎不可读。

我在找的是类似ant的JUnitReport任务。有没有可用的那里?

回答

25

事实上,在每个版本生成整个网站显然不是一种选择。但问题是,mvn surefire-report:report-only不会创建css/*。css文件,因此会导致难看的结果。这是记录在SUREFIRE-616(并不意味着会发生,虽然)。就个人而言,我不使用HTML有报道称,这样我可以忍受的,但是这不是一个很好的答案所以这里是一个基于Ant任务(*叹*)解决方法:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>test-reports</id> 
     <phase>test</phase> 
     <configuration> 
      <tasks> 
      <junitreport todir="target/surefire-reports"> 
       <fileset dir="target/surefire-reports"> 
       <include name="**/*.xml"/> 
       </fileset> 
       <report format="noframes" todir="target/surefire-reports"/> 
      </junitreport> 
      </tasks> 
     </configuration> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     </execution> 
    </executions> 
    <dependencies> 
     <dependency> 
     <groupId>ant</groupId> 
     <artifactId>ant-junit</artifactId> 
     <version>1.6.2</version> 
     </dependency> 
    </dependencies> 
    </plugin> 

更新:我最初的想法是“按需”运行Maven AntRun插件生成报告......但这不是我发布的内容,我将它绑定到test阶段......但我没有考虑失败测试的情况(这会停止构建并阻止AntRun插件的执行)。所以,无论是:

  1. 不要绑定AntRun插件的test阶段,移动execution外的配置和调用mvn antrun:run在命令行上以产生想要当的报告。

  2. 或使用测试魔力的testFailureIgnore选项并将其设置为true在万无一失插件配置:

    <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <configuration> 
        <testFailureIgnore>true</testFailureIgnore> 
        </configuration> 
    </plugin> 
    
  3. 或设置使用-D参数从命令行此表达式:

    $ mvn test -Dmaven.test.failure.ignore=true 
    

我认为选项#1是最好的选择,你不一定要生成报告(特别是当测试通过)和系统地生成它们可能会减缓建设的长期性。我会按需求生成它们。

+0

是否打开子进程或只运行蚂蚁嵌入?如果这只是嵌入蚂蚁,它的任务,这正是我需要的。 – 2010-05-17 10:05:18

+0

@jimmy它在同一个进程中运行ant任务。 – 2010-05-17 10:59:49

+0

感谢这正是我需要知道的! – 2010-05-19 10:07:02

4

感谢帕斯卡,我已经找到了新的改进方案做我想做的事:

<plugin> 
    <!-- Extended Maven antrun plugin --> 
    <!-- https://maven-antrun-extended-plugin.dev.java.net/ --> 
    <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="target/surefire-reports"> 
       <fileset dir="target/surefire-reports"> 
       <include name="**/*.xml"/> 
       </fileset> 
       <report format="noframes" todir="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> 

这个版本使用的蚂蚁的新版本以及所有最好的。但是,当测试失败时,我仍然没有找到生成测试报告的方法。我应该怎么做?

+0

您是否在测试失败后获得生成报告的方式? – masT 2013-11-28 09:27:56

+0

您好,在MAVEN中配置了ANT后,Surefire报告在html报告中生成了重复测试。我怎样才能避免这种情况? – royki 2017-06-09 07:22:54

1

您可以设置-Dmaven.test.failure.ignore=true在测试失败时生成测试报告。

2

这里是我做到了使用目标网站Maven的万无一失:报告

<reporting> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-report-plugin</artifactId> 
       <version>2.16</version> 
       <configuration> 
        <showSuccess>false</showSuccess> 
        <outputDirectory>${basedir}/target/surefire-reports</outputDirectory> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-site-plugin</artifactId> 
       <version>3.3</version> 
       <configuration> 
        <outputDirectory>${basedir}/target/surefire-reports</outputDirectory> 
       </configuration> 
      </plugin> 
     </plugins> 
    </reporting> 

</project> 
31

这是我做的:

# Run tests and generate .xml reports 
mvn test 

# Convert .xml reports into .html report, but without the CSS or images 
mvn surefire-report:report-only 

# Put the CSS and images where they need to be without the rest of the 
# time-consuming stuff 
mvn site -DgenerateReports=false 

去瞄准/网站/报告的surefire-report.html。

经过测试运行后,其余的两个运行约3.5秒对我来说。

希望有所帮助。请享用!

+1

这应该被视为取得成果和答案的最简单方法。 – vikramvi 2016-12-05 10:14:33

1

创建一个新的Maven运行配置,并与目标=>

surefire-report:report site -DgenerateReports=false 

这可以帮助你与CSS更好的报表视图。