1. 程式人生 > >testNG之測試報告

testNG之測試報告

測試報告

  執行完測試用例之後,會在專案的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進行美化:

   現在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,以圖形化的介面展示測試結果:

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