2017-01-09 66 views
1

我有一個可以運行所有單元測試和覆蓋率的ready文件。腳本生成coverage.json文件。我喜歡使用cobertura插件(https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin),所以我一直在尋找一種解決方案來創建適合cobertura的文件格式,它是xml。不能從lcov.info或Jenkins VirtualEnv中的Coverage.json文件生成cobertura.xml文件

我一切都在VirutalEnv(https://wiki.jenkins-ci.org/display/JENKINS/ShiningPanda+Plugin)!

我試過這個命令:istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/https://github.com/gotwarlost/istanbul

而且結果如下:

13:26:09 [...] 
13:26:09 210 passing (1s) 
13:26:09 
13:26:09 ============================================================================= 
13:26:09 Writing coverage object [/var/lib/jenkins/workspace/unit-tests-client-javascript/coverage/coverage.json] 
13:26:09 Writing coverage reports at [/var/lib/jenkins/workspace/unit-tests-client-javascript/coverage] 
13:26:09 ============================================================================= 
13:26:09 
13:26:09 =============================== Coverage summary =============================== 
13:26:09 Statements : 96.88% (279/288) 
13:26:09 Branches  : 86.24% (94/109), 1 ignored 
13:26:09 Functions : 100% (57/57) 
13:26:09 Lines  : 96.88% (279/288) 
13:26:09 ================================================================================ 
13:26:11 + istanbul report cobertura --root /var/lib/jenkins/workspace/unit-tests-client-javascript/coverage/coverage.json --dir coverage/ 
13:26:11 Done 
13:26:11 [Cobertura] Publishing Cobertura coverage report... 
13:26:11 Publishing Cobertura coverage results... 
13:26:11 Cobertura coverage report found. 
13:26:11 Finished: SUCCESS 

然而,創建的Cobertura-coverage.xml文件幾乎是空的!

<?xml version="1.0" ?> 
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd"> 
<coverage lines-valid="0" lines-covered="0" line-rate="1" branches-valid="0" branches-covered="0" branch-rate="1" timestamp="1483968808589" complexity="0" version="0.1"> 
<sources> 
    <source>/var/lib/jenkins/workspace/unit-tests-client-javascript</source> 
</sources> 
<packages> 
</packages> 

和代碼的Cobertura代碼覆蓋工具顯示了什麼! 0!

我也嘗試使用LCOV到的Cobertura-XML(https://github.com/eriwen/lcov-to-cobertura-xml),但結果如下:

14:33:24 [...] 
14:33:24 + git clone https://github.com/eriwen/lcov-to-cobertura-xml.git 
14:33:24 Cloning into 'lcov-to-cobertura-xml'... 
14:33:27 + pip install /var/lib/jenkins/workspace/unit-tests-client-javascript/lcov-to-cobertura-xml/. 
14:33:27 Processing ./lcov-to-cobertura-xml 
14:33:27 Requirement already satisfied (use --upgrade to upgrade): lcov-cobertura==1.6 from file:///var/lib/jenkins/workspace/unit-tests-client-javascript/lcov-to-cobertura-xml in /var/lib/jenkins/shiningpanda/jobs/e24105b6/virtualenvs/d41d8cd9/lib/python2.7/site-packages 
14:33:27 Building wheels for collected packages: lcov-cobertura 
14:33:27 Running setup.py bdist_wheel for lcov-cobertura: started 
14:33:28 Running setup.py bdist_wheel for lcov-cobertura: finished with status 'done' 
14:33:28 Stored in directory: /var/lib/jenkins/.cache/pip/wheels/06/91/3e/ead128a367068e0e33fd380f090030c829dff190d4099a2e3b 
14:33:28 Successfully built lcov-cobertura 
14:33:28 + lcov_cobertura coverage/lcov.info --base-dir /var/lib/jenkins/workspace/unit-tests-client-javascript --excludes /var/lib/jenkins/workspace/unit-tests-client-javascript/test --output coverage/coverage.xml 
14:33:28 /tmp/shiningpanda2010602884229553447.sh: line 40: lcov_cobertura: command not found 
14:33:28 Build step 'Virtualenv Builder' marked build as failure 
14:33:28 Finished: FAILURE 

我在做什麼錯?浪費了很多小時試圖解決這個問題!也許我應該使用另一個可以將coverage.json文件轉換爲代碼覆蓋率的圖表或圖形可視化的工具?

回答

2

好,我找到了解決辦法...

我的命令是:istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/

我改成了istanbul report cobertura --root $WORKSPACE/coverage --dir $WORKSPACE

而現在它完美的作品。問題可能是設置根目錄和目錄到同一個文件夾。不知道爲什麼它這樣工作,但嘿,它解決了:)。