testNG之測試報告


原文:https://www.cnblogs.com/yuan-yuan/p/4503524.html

 

 

測試報告

  執行完測試用例之后,會在項目的test-output(默認目錄)下生成測試報告

 

打開index.html文件,測試結果摘要,包括:套件名、測試用例成功數、測試用例失敗數、測試用例忽略數和testng.xml文件

 

測試用例都成功的話,測試結果以綠底標志:

 

測試用例有失敗的話,測試結果以紅底標志:

 

點擊"Link"鏈接,可以查看testng.xml文件的內容:

復制代碼
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite verbose="0" name="Suite1" parallel="false">
  <test name="testNG1" preserve-order="false">
    <classes>
      <class name="testNG1"/>
      <class name="testNG2"/>
      <class name="testNG3"/>
    </classes>
  </test>
</suite> 
復制代碼

 

點擊"Suite1"鏈接,可以查看更詳細的信息:

 

點擊"Results"鏈接,可以查看詳細的測試結果:

 

testng-xslt

testNG自帶生成的測試報告不太美觀,可以使用testng-xslt進行美化:

1、下載testng-xslt包,http://testng-xslt.googlecode.com/files/testng-xslt-1.1.zip

   現在google可能訪問不了,可到我的網盤里下載http://pan.baidu.com/s/1bn4hR9H

2、復制testng-results.xsl(testng-xslt-1.1\src\main\resources)文件到test-output目錄下

3、復制saxon-8.7.jar(testng-xslt-1.1\lib)文件到project的lib目錄下(沒有的話,自己新建)

4、安裝ant,http://mirror.bit.edu.cn/apache/ant/binaries/apache-ant-1.9.4-bin.zip

5、配置好環境變量PATH

6、在project目錄下,新建build.xml文件,內容如下:

復制代碼
<project name="testNG" basedir="." >
    <property name="lib.dir" value="lib" />
    <path id="test.classpath" >
         <!-- adding the saxon jar to your classpath -->
        <fileset dir="${lib.dir}" includes="*.jar" />
    </path>
    <target name="transform" >
        <!-- 需要根據自己的環境進行配置(將E:/workspace/testNG/替換成你自己project的目錄) -->
        <xslt in="E:/workspace/testNG/test-output/testng-results.xml" style="E:/workspace/testNG/test-output/testng-results.xsl"
  out="E:/workspace/testNG/test-output/index1.html" >
             <!-- 需要根據自己的環境進行配置(將E:/workspace/testNG/替換成你自己project的目錄) -->
            <param name="testNgXslt.outputDir" expression="E:/workspace/testNG/test-output/" />
            <classpath refid="test.classpath" />
        </xslt>
    </target>
</project> 
復制代碼

7、在cmd里,切換到project的目錄,執行ant transform:

8、到配置的路徑下,打開生成的文件index1.html,以圖形化的界面展示測試結果:

信息都差不多,只是頁面優化,更加美觀了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM