2015-07-11 59 views
1

我用摩卡得到單元測試結果和伊斯坦布爾獲得代碼覆蓋率。我正在使用grunt來運行這些任務。它工作正常。我還使用grunt-sonar-runner插件將這些結果導入聲納。目前代碼覆蓋率已導入,但單元測試結果並非如此。在生成過程中,聲納報告我:進口摩卡單位測試結果sonarqube

20:40:19.410 WARN - Test result will not be saved for test class "Account Controllers User Controller forgot password", because SonarQube associated resource has not been found using file name: "Account Controllers User Controller forgot password.js" 
20:40:19.411 WARN - Test result will not be saved for test class "Account Controllers User Controller login", because SonarQube associated resource has not been found using file name: "Account Controllers User Controller login.js" 
20:40:19.413 WARN - Test result will not be saved for test class "Account Controllers User Controller logout", because SonarQube associated resource has not been found using file name: "Account Controllers User Controller logout.js" 

因此,聲納不保存單元測試結果。我嘗試在2.2中更改javascript插件版本,或者在5.1.1中升級聲納系統,但問題是相同的。我也嘗試重命名所有describe函數以在文件夾之間形成文件的正確路徑.(例如:test.unit.controllers.filename.而我意識到它只適用於一個測試,如果您有超過1個測試,它將不起作用

配置:
*聲納(4.5.2)
* JavaScript的插件(2.7)

NPM模塊:
*摩卡聲納 - 報道(^ 0.1.3)
*摩卡:(^ 2.1 .0)
* grunt-mocha-test(^ 0.12.7)

回答

3

我實際上獲得了伊斯坦布爾的代碼覆蓋率和摩卡單元測試結果。確實,摩卡(xunit記者)失敗了。它只適用於在文件夾和文件名之間正確設置了.的一個測試和一個類名。 這裏是摩卡和繁重的解決方案,請照做這些步驟,文件和文件夾的命名方面:
1.使用NPM模塊:sonar-mocha-reporter
2.在您的package.json添加這些行:

"config": { 
     "mocha-sonar-reporter": { 
      "classname": "Test", 
      "testdir": "test", 
      "outputfile": "report/TEST-results.xml" 
     } 
    } 

3.定義NPM測試CMD(I所定義的咕嚕任務運行與咕嚕mocha-test插件測試):

"scripts": { 
     "test": "grunt runTests" 
    } 

4.定義咕嚕任務:

module.exports = function(grunt) { 

     grunt.config.set('mochaTest', { 
      test: { 
       options: { 
        timeout:   6000, 
        reporter:   'mocha-sonar-reporter', 
        quiet:    false, 
        clearRequireCache: true 
       }, 
       src:  ['test/**/*.js'] 
      } 
     }); 

     grunt.loadNpmTasks('grunt-mocha-test'); 
    }; 

5.配置與咕嚕sonar-runner插件報表並添加這些行,如果它尚未的情況下(選項對象):

dynamicAnalysis: 'reuseReports', 
    tests: 'test', 
    javascript: { 
     jstestdriver: { 
      reportsPath: 'report' 
     }, 
     lcov: { 
      reportPath: 'report/lcov.info' 
     } 
    }, 
  • 與運行測試npm test命令。與gruntgulp,它將無法正常工作。
  • 配置:
    *聲納(4.5.2)
    * JavaScript的插件(2.7)

    NPM模塊:
    *摩卡聲納 - 報道(^ 0.1.3)
    *摩卡(^ 2.1.0)
    *咕嚕 - 摩卡測試(^ 0.12.7)

    有用的文檔這幫助我解決這個問題:sonarqube javascript plugin docs