在sonarqube导入摩卡单位测试结果 [英] import mocha unit tests result in sonarqube
问题描述
grunt-sonar-runner
插件将这些结果导入声纳。目前代码覆盖率已导入,但单元测试结果并非如此。在生成过程中,声纳报告给我: 20:40:19.410 WARN - 测试结果不会保存在测试类账户控制器用户控制器忘记密码,因为尚未使用文件名称找到SonarQube相关资源:账户控制器用户控制器忘记密码.js
20:40:19.411警告 - 测试结果不会保存在测试类中帐户控制器用户控制器登录,因为尚未使用文件名帐户控制器用户控制器login.js找到SonarQube相关资源
20:40:19.413警告 - 测试结果不会保存在测试类帐户控制器用户控制器logout.js
找不到SonarQube相关资源
正因为如此,声纳不保存单元测试结果。我尝试在2.2中更改javascript插件版本,或者在5.1.1中升级声纳系统,但问题是相同的。我还尝试重命名所有 describe
函数,以在文件夹之间形成文件的正确路径(例如:<
配置:
* sonar(4.5.2)
* javascript插件(2.7)
npm模块:
* mocha-sonar-reporter(^ 0.1.3)
* mocha:(^ 2.1.0)
* grunt -mocha-test(^ 0.12.7)
实际上,我用isochabul获得代码覆盖率,并使用mocha获得了单元测试结果。 ,mocha(xunit reporter)失败,只有当你有一个测试和一个正确设置了。
的文件夹和文件名之间的类名
时才有效。使用nocha模块: sonar-mocha-reporter
2.加t
config:{
mocha-sonar-reporter:{
classname:Test,
testdir:test,
outputfile:report / TEST-results.xml
}
}
3。定义npm test cmd(我定义了一个使用grunt mocha-test
插件运行测试的grunt任务):
scripts:{
test:grunt runTests
}
4。定义grunt任务:
module.exports = function(grunt){
grunt.config。 set('mochaTest',{
test:{
options:{
timeout:6000,
记者:'mocha-sonar-reporter',
quiet:false ,
clearRequireCache:true
},
src:['test / ** / *。js']
}
});
grunt.loadNpmTasks('grunt-mocha-test');
};
5。使用grunt sonar-runner
插件配置您的报告,并添加以下这些行(如果还不是案例的话):
< pre $
dynamicAnalysis:'reuseReports',
tests:'test',
javascript:{
jstestdriver:{
reportsPath:'report'
},
lcov:{
reportPath:'report / lcov.info'
}
},
pre> - 使用
npm test
命令运行测试。grunt
或gulp
,它将不起作用。
配置:
* sonar(4.5.2)
* javascript插件(2.7)
$ b $ (^ 0.1.3)
*摩卡:(^ 2.1.0)
* mocha-sonar-reporter(^ 0.1.3) grunt-mocha-test(^ 0.12.7)
帮助我解决这个问题的有用文档: sonarqube javascript plugin docs
I use mocha to get unit tests results and istanbul to get code coverage. I'm using grunt to run these tasks. It works fine. I'm also using grunt-sonar-runner
plugin to import these result in sonar. Currently code coverage is imported but that is not the case for unit tests results. During the build, sonar report me this :
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"
Because of this, sonar don't save unit tests results. I tryed to change the javascript plugin version in 2.2, or upgrade sonar system in 5.1.1 but the problem is the same. I also try to rename all describe
function to form the right path to the file with .
between folders (e.g: test.unit.controllers.filename.
And I realized that it works for only one test. If you have more than 1 tests, it will not work.
configuration:
* sonar (4.5.2)
* javascript plugin (2.7)
npm modules:
* mocha-sonar-reporter (^0.1.3)
* mocha: (^2.1.0)
* grunt-mocha-test (^0.12.7)
I actually get code coverage with istanbul and unit tests results with mocha. Indeed, the mocha (xunit reporter) fails. It only works if you have one test and a classname correctly set with .
between folders and filename.
Here is the solution with mocha and grunt, please follow exactly these steps and respect naming of files and folders :
1. Use npm module : sonar-mocha-reporter
2. Add these lines in your package.json:
"config": {
"mocha-sonar-reporter": {
"classname": "Test",
"testdir": "test",
"outputfile": "report/TEST-results.xml"
}
}
3. Define npm test cmd (I defined a grunt task to run test with grunt mocha-test
plugin ):
"scripts": {
"test": "grunt runTests"
}
4. Define the grunt task:
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. Configure your reporting with grunt sonar-runner
plugin and add these lines if it not already the case (options object):
dynamicAnalysis: 'reuseReports',
tests: 'test',
javascript: {
jstestdriver: {
reportsPath: 'report'
},
lcov: {
reportPath: 'report/lcov.info'
}
},
- Run your test with
npm test
command. withgrunt
orgulp
, it won't work.
configuration:
* sonar (4.5.2)
* javascript plugin (2.7)
npm modules:
* mocha-sonar-reporter (^0.1.3)
* mocha: (^2.1.0)
* grunt-mocha-test (^0.12.7)
Useful documentation which helped me to solve this problem : sonarqube javascript plugin docs
这篇关于在sonarqube导入摩卡单位测试结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!