Lou*_*iro 3 javascript mocha.js gruntjs sonarqube
我使用 mocha 来获取单元测试结果,使用 istanbul 来获取代码覆盖率。我正在使用 grunt 来运行这些任务。它工作正常。我也在使用grunt-sonar-runner插件将这些结果导入声纳。当前代码覆盖率已导入,但单元测试结果并非如此。在构建过程中,声纳向我报告:
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"
Run Code Online (Sandbox Code Playgroud)
因此,声纳不保存单元测试结果。我尝试在 2.2 中更改 javascript 插件版本,或在 5.1.1 中升级声纳系统,但问题是相同的。我还尝试重命名所有describe函数以形成文件.夹之间的文件的正确路径(例如:test.unit.controllers.filename.我意识到它仅适用于一个测试。如果您有超过 1 个测试,它将不起作用。
配置:
*声纳(4.5.2)
*javascript插件(2.7)
npm 模块:
* mocha-sonar-reporter (^0.1.3)
* mocha: (^2.1.0)
* grunt-mocha-test (^0.12.7)
我实际上得到了伊斯坦布尔的代码覆盖率和 mocha 的单元测试结果。事实上,mocha(xunit 记者)失败了。只有.在文件夹和文件名之间正确设置了一个测试和类名时,它才有效。这是 mocha 和 grunt 的解决方案,请完全按照这些步骤并尊重文件和文件夹的命名:
1. 使用 npm 模块:sonar-mocha-reporter
2. 在 package.json 中添加这些行:
"config": {
"mocha-sonar-reporter": {
"classname": "Test",
"testdir": "test",
"outputfile": "report/TEST-results.xml"
}
}
Run Code Online (Sandbox Code Playgroud)
3. 定义 npm test cmd(我定义了一个 grunt 任务来运行带有 gruntmocha-test插件的测试):
"scripts": {
"test": "grunt runTests"
}
Run Code Online (Sandbox Code Playgroud)
4.定义grunt任务:
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');
};
Run Code Online (Sandbox Code Playgroud)
5. 使用 gruntsonar-runner插件配置您的报告并添加这些行(如果不是这样的话)(选项对象):
dynamicAnalysis: 'reuseReports',
tests: 'test',
javascript: {
jstestdriver: {
reportsPath: 'report'
},
lcov: {
reportPath: 'report/lcov.info'
}
},
Run Code Online (Sandbox Code Playgroud)
npm test命令运行您的测试。使用grunt或gulp,它将不起作用。配置:
*声纳(4.5.2)
*javascript插件(2.7)
npm 模块:
* mocha-sonar-reporter (^0.1.3)
* mocha: (^2.1.0)
* grunt-mocha-test (^0.12.7)
帮助我解决这个问题的有用文档:sonarqube javascript plugin docs
| 归档时间: |
|
| 查看次数: |
8825 次 |
| 最近记录: |