2010-05-17 56 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更好的報表視圖。