<bdo id='S5uWj'></bdo><ul id='S5uWj'></ul>
    <tfoot id='S5uWj'></tfoot>
    <i id='S5uWj'><tr id='S5uWj'><dt id='S5uWj'><q id='S5uWj'><span id='S5uWj'><b id='S5uWj'><form id='S5uWj'><ins id='S5uWj'></ins><ul id='S5uWj'></ul><sub id='S5uWj'></sub></form><legend id='S5uWj'></legend><bdo id='S5uWj'><pre id='S5uWj'><center id='S5uWj'></center></pre></bdo></b><th id='S5uWj'></th></span></q></dt></tr></i><div id='S5uWj'><tfoot id='S5uWj'></tfoot><dl id='S5uWj'><fieldset id='S5uWj'></fieldset></dl></div>

    <legend id='S5uWj'><style id='S5uWj'><dir id='S5uWj'><q id='S5uWj'></q></dir></style></legend>
    1. <small id='S5uWj'></small><noframes id='S5uWj'>

        导入 mocha 单元测试导致 sonarqube

        import mocha unit tests result in sonarqube(导入 mocha 单元测试导致 sonarqube)

          <bdo id='5WlNE'></bdo><ul id='5WlNE'></ul>

          • <legend id='5WlNE'><style id='5WlNE'><dir id='5WlNE'><q id='5WlNE'></q></dir></style></legend>

            1. <i id='5WlNE'><tr id='5WlNE'><dt id='5WlNE'><q id='5WlNE'><span id='5WlNE'><b id='5WlNE'><form id='5WlNE'><ins id='5WlNE'></ins><ul id='5WlNE'></ul><sub id='5WlNE'></sub></form><legend id='5WlNE'></legend><bdo id='5WlNE'><pre id='5WlNE'><center id='5WlNE'></center></pre></bdo></b><th id='5WlNE'></th></span></q></dt></tr></i><div id='5WlNE'><tfoot id='5WlNE'></tfoot><dl id='5WlNE'><fieldset id='5WlNE'></fieldset></dl></div>

              • <small id='5WlNE'></small><noframes id='5WlNE'>

                <tfoot id='5WlNE'></tfoot>
                  <tbody id='5WlNE'></tbody>
                1. 本文介绍了导入 mocha 单元测试导致 sonarqube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用 mocha 来获取单元测试结果,并使用 istanbul 来获取代码覆盖率.我正在使用 grunt 来运行这些任务.它工作正常.我还使用 grunt-sonar-runnerplugin 将这些结果导入声纳.当前代码覆盖率已导入,但单元测试结果并非如此.在构建期间,声纳向我报告:

                  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-runnerplugin 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"
                  

                  因此,声纳不保存单元测试结果.我尝试在 2.2 中更改 javascript 插件版本,或在 5.1.1 中升级声纳系统,但问题是一样的.我还尝试重命名所有 describe 函数,以在文件夹之间使用 . 形成文件的正确路径(例如:test.unit.controllers.filename. 而且我意识到它只适用于一个测试.如果你有超过 1 个测试,它就不起作用了.

                  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.

                  配置:
                  * 声纳 (4.5.2)
                  * javascript 插件 (2.7)

                  configuration:
                  * sonar (4.5.2)
                  * javascript plugin (2.7)

                  npm 模块:
                  * mocha-sonar-reporter (^0.1.3)
                  * 摩卡:(^2.1.0)
                  * 咕噜摩卡测试 (^0.12.7)

                  npm modules:
                  * mocha-sonar-reporter (^0.1.3)
                  * mocha: (^2.1.0)
                  * grunt-mocha-test (^0.12.7)

                  推荐答案

                  我实际上得到了 istanbul 的代码覆盖率和 mocha 的单元测试结果.事实上,摩卡咖啡(xunit 记者)失败了.仅当您在文件夹和文件名之间使用 . 正确设置了一个测试和类名时,它才有效.这是 mocha 和 grunt 的解决方案,请完全按照这些步骤操作并尊重文件和文件夹的命名:
                  1. 使用 npm 模块:sonar-mocha-reporter
                  2. 在你的 package.json 中添加这些行:

                  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.定义 npm test cmd(我定义了一个 grunt 任务来使用 grunt mocha-test 插件运行测试):

                  3. Define npm test cmd (I defined a grunt task to run test with grunt mocha-test plugin ):

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

                  4.定义 grunt 任务:

                  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.使用 grunt sonar-runner 插件配置您的报告,如果还没有,请添加这些行(选项对象):

                  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'
                         }
                     },
                  

                  1. 使用 npm test 命令运行您的测试.使用 gruntgulp 将无法正常工作.
                  1. Run your test with npm test command. with grunt or gulp, it won't work.

                  配置:
                  * 声纳 (4.5.2)
                  * javascript 插件 (2.7)

                  configuration:
                  * sonar (4.5.2)
                  * javascript plugin (2.7)

                  npm 模块:
                  * mocha-sonar-reporter (^0.1.3)
                  * 摩卡:(^2.1.0)
                  * 咕噜摩卡测试 (^0.12.7)

                  npm modules:
                  * mocha-sonar-reporter (^0.1.3)
                  * mocha: (^2.1.0)
                  * grunt-mocha-test (^0.12.7)

                  帮助我解决这个问题的有用文档:sonarqube javascript 插件文档

                  Useful documentation which helped me to solve this problem : sonarqube javascript plugin docs

                  这篇关于导入 mocha 单元测试导致 sonarqube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                  How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                  Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                  SQL Query DocumentDB in Azure Functions by an integer not working(通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用)
                  Azure Functions [JavaScript / Node.js] - HTTP call, good practices(Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践)
                  Azure Functions - Import Custom Node Module(Azure Functions - 导入自定义节点模块)

                    1. <i id='rs5g6'><tr id='rs5g6'><dt id='rs5g6'><q id='rs5g6'><span id='rs5g6'><b id='rs5g6'><form id='rs5g6'><ins id='rs5g6'></ins><ul id='rs5g6'></ul><sub id='rs5g6'></sub></form><legend id='rs5g6'></legend><bdo id='rs5g6'><pre id='rs5g6'><center id='rs5g6'></center></pre></bdo></b><th id='rs5g6'></th></span></q></dt></tr></i><div id='rs5g6'><tfoot id='rs5g6'></tfoot><dl id='rs5g6'><fieldset id='rs5g6'></fieldset></dl></div>

                        <legend id='rs5g6'><style id='rs5g6'><dir id='rs5g6'><q id='rs5g6'></q></dir></style></legend>

                          <bdo id='rs5g6'></bdo><ul id='rs5g6'></ul>

                        • <tfoot id='rs5g6'></tfoot>

                          <small id='rs5g6'></small><noframes id='rs5g6'>

                            <tbody id='rs5g6'></tbody>