2011-11-07 74 views
2

我正在使用測試框架(py.test)以非Java語言(Python)進行一些單元/集成測試,該測試框架能夠生成JUnit樣式的XML輸出,例如像這樣:將JUnit樣式的XML測試輸出呈現爲HTML

<?xml version="1.0" encoding="utf-8"?> 
<testsuite name="" errors="0" failures="0" skips="4" tests="4" time="75.956"> 
    <testcase classname="daemon_ping_test.SimpleDaemonTestCase" name="test_daemon_runs_plugin" time="0.000185012817383"> 
     <skipped type="pytest.skip" message="skipped temporarily">/usr/local/lib/python2.7/dist-packages/pytest-2.1.3-py2.7.egg/_pytest/unittest.py:88: Skipped: skipped temporarily</skipped> 
    </testcase> 
    <testcase classname="libvirt_handler_test.LibvirtHandlerTestcase" name="test_domain_with_iscsi" time="0.00244903564453"> 
    </testcase> 
    <testcase classname="libvirt_handler_test.LibvirtHandlerTestcase" name="test_libvirt_controller" time="0.00547981262207"> 
    </testcase> 
     <testcase classname="libvirt_handler_test.LibvirtHandlerTestcase" name="test_libvirt_get_vmid_by_storage" time="0.000415086746216"> 
     <skipped type="pytest.skip" message="temporarily disabled">/usr/local/lib/python2.7/dist-packages/pytest-2.1.3-py2.7.egg/_pytest/unittest.py:88: Skipped: temporarily disabled</skipped> 
    </testcase> 
    <testcase classname="test_integration.StorageTests" name="test_1_CreateTemplate" time="73.7471599579"></testcase> 
    <testcase classname="test_integration.StorageTests" name="test_2_CreateStorageVol" time="0.000442981719971"> 
     <skipped type="pytest.skip" message="temporarily skipped">/usr/local/lib/python2.7/dist-packages/pytest-2.1.3-py2.7.egg/_pytest/unittest.py:88: Skipped: temporarily skipped</skipped> 
    </testcase> 
    <testcase classname="test_integration.StorageTests" name="test_3_StorageVolMap" time="0.000404119491577"> 
     <skipped type="pytest.skip" message="temporarily skipped">/usr/local/lib/python2.7/dist-packages/pytest-2.1.3-py2.7.egg/_pytest/unittest.py:88: Skipped: temporarily skipped</skipped> 
    </testcase> 
    <testcase classname="test_integration.StorageTests" name="test_4_RemoveTemplate" time="1.97415280342"> 
    </testcase> 
</testsuite> 

現在我想要將這些結果呈現給人類可讀的HTML文件。有沒有什麼工具可以做到這一點?

回答

2

螞蟻可能是最簡單的方法。您可以使用junit-report任務,就像這樣..

<junitreport todir="./reports"> 
    <fileset dir="."> 
    <include name="**/*.xml" /> 
    </fileset> 
    <report format="frames" todir="./reports/html" /> 
</junitreport> 
1

另一種方法是使用XSLT處理器來編寫它。定義一個XSL樣式表,然後運行它:

xsltproc --output tests.html your.xsl path/to/tests.xml 
+0

(我想我真正從內JUnit的罐子1使用的XSL,所以HTML報告幾乎是一樣的,如果它是由螞蟻運行)。 – Brett