如何用 testNG 生成測試報告


原文地址https://testerhome.com/topics/3473

總結一下testNG生成報告的三種方式,基本都是我直接轉載的,沒有補充就不說了,有補充的我會加以說明的(這里直說生成報告,不說怎么寫測試用例的事兒)

第一種:生成原始報告http://www.cnblogs.com/TankXiao/p/3888070.html

這里的xml用最簡單版本的即可,如下:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
    <test name="test12">
        <classes>
            <class name="TankLearn2.Learn.TestNGLearn1" />
        </classes>
    </test>
</suite>

 

使用的時候只要修改對應的class name就可以了,參考鏈接中的文章完全可以出來結果,生成的報告是最原始的如下圖:

 

 

 

第二種:使用TestNG-xslt美化測試報告 http://www.tuicool.com/articles/FJzYBr

這里的xml如下:

<?xml version="1.0" encoding="UTF-8"?>

<project name="testTng" basedir="." default="transform">

    <property name="lib.dir" value="lib" />

    <path id=".classpath">

        <!-- adding the saxon jar to your classpath -->

        <fileset dir="${lib.dir}" includes="*.jar" />

    </path>

    <target name="transform">

        <xslt
            in="E:\Users\Administrator\workspace\testNG_test\test-output\testng-results.xml"
            style="E:\Users\Administrator\workspace\testNG_test\test-output\testng-results.xsl"

            out="E:/Users/Administrator/workspace/testNG_test/test-output/index1.html">

            <!-- you need to specify the directory here again -->

            <param name="testNgXslt.outputDir"
                expression="E:/Users/Administrator/workspace/testNG_test/test-output" />

            <classpath refid=".classpath" />

        </xslt>

    </target>

</project>

 

只要替換對應的路徑就行。生成的報告就美觀多了,如下圖這樣的:

 

 

第三種:reportNG如何生成測試報告 https://testerhome.com/topics/2180

需要導入的jar包

 

 

這里使用的xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="test" parallel="true">

    <test name="test" preserver-order="true">
        <classes>
            <class name="testNG_test.test_testNG" />
        </classes>

        <listeners>
            <listener class-name="org.uncommons.reportng.HTMLReporter" />
            <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
        </listeners>
    </test> <!-- Test -->
</suite> <!-- Suite -->

 

使用的時候只要修改對應的class name就行了 這樣執行生成的報告是如下圖這樣的:

 

 

appium測試的時候可以用testNG框架,然后直接右鍵testng.xml就可以生成美觀的測試報告的,參考這個鏈接https://testerhome.com/topics/1639里面可以並行執行測試用例。
現在我用的都是第三種方法,簡單美觀!

最后感謝testerhome這個平台,里面能學到很多東西,也能讓我把學到的東西進行總結記錄,希望我的總結能對大家有所幫助


免責聲明!

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



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