Как импортировать юнит-тест кармы в SonarQube - PullRequest
0 голосов
/ 28 апреля 2020

Я использую SonarQube с приложением angular. Я создаю отчет о модульных тестах и ​​отчет о покрытии, которые я хочу импортировать в SonarQube.

Я использую karma-junit-reporter для создания отчета xml для тестов.

Вот моя карма .conf. js:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: "",
    frameworks: ["jasmine", "@angular-devkit/build-angular"],
    plugins: [
      require("karma-jasmine"),
      require("karma-chrome-launcher"),
      require("karma-jasmine-html-reporter"),
      require("karma-coverage-istanbul-reporter"),
      require("karma-junit-reporter"),
      require("@angular-devkit/build-angular/plugins/karma"),
    ],
    client: {
      clearContext: false, // leave Jasmine Spec Runner output visible in browser,
      jasmine: {
        random: false,
      },
    },
    coverageIstanbulReporter: {
      dir: require("path").join(__dirname, "coverage"),
      reports: ["html", "lcovonly"],
      fixWebpackSourcePaths: true,
    },
    junitReporter: {
      outputDir: require("path").join(__dirname, "coverage"), // results will be saved as $outputDir/$browserName.xml
      outputFile: "junit-test.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
      suite: "", // suite will become the package name attribute in xml testsuite element
      useBrowserName: false, // add browser name to report and classes names
      nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
      classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
      properties: {}, // key value pair of properties to add to the <properties> section of the report
      xmlVersion: 1, // use '1' if reporting to be per SonarQube 6.2 XML format
    },
    reporters: ["progress", "kjhtml", "junit"],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ["Chrome"],
    singleRun: true,
  });
};

А в моем sonar-project.properties:

# path where code coverage is stored (created by ng tests command)
sonar.typescript.lcov.reportPaths=./coverage/lcov.info
sonar.genericcoverage.unitTestReportPaths=./coverage/junit-test.xml
sonar.testExecutionReportPaths=./coverage/junit-test.xml

Покрытие хорошо импортировано, но я не могу получить результат модульного теста в SonarQube, количество пройденных / неудачных испытаний.

Мой xml файл выглядит так:

<?xml version="1.0"?>
<unitTest version="1">
  <file path="fixedString">
    <testCase name="ListComponent should create" duration="128"/>
    <testCase name="ListComponent should run #ngOnInit()" duration="63"/>
  ...

Что здесь не так?

...