Must-share information (formatted with Markdown):
- which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
- what are you trying to achieve
- what have you tried so far to achieve this
VERSIONS-
Enterprise EditionVersion 8.7 (build 41497
SonarScanner 4.3.0.2102 18:50:54 INFO:
Java 11.0.3 AdoptOpenJDK (64-bit) 18:50:54 INFO: Linux 3.10.0-1127.18.2.el7.x86_64 amd64)
package.json
"build": "ng build && webpack",
"test": "mocha && ng test",
"lint": "ng lint",
"coverage": "nyc --reporter=text --reporter=lcov npm run test",
"test-with-coverage": "npx nyc --reporter=html mocha"
"devDependencies": {
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-sonarqube-reporter": "^1.4.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"karma-junit-reporter": "^1.2.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-phantomjs-shim": "^1.4.0",
"mocha": "^8.3.2",
}}
Required deatails from karma file
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-mocha-reporter')
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-sonarqube-reporter'),
require('karma-junit-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
],
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
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
testexecution: 'unit'
} ,
reporters: ['progress', 'kjhtml', 'junit','mocha', 'sonarqube'],
format of sonar o/p —
<testsuite name="Chrome Headless 90.0.4430.212 (Linux x86_64)" package="" timestamp="2021-06-18T11:09:55" id="0" hostname="*" tests="" errors="*" failures="*" time="*">
<properties>
<property name="browser.fullName" value="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/90.0.4430.212 Safari/537.36"/>
</properties>
<testcase name="HeaderComponent should test darkThemeClicked" time="0.241" classname="HeaderComponent"/>
<testcase name="HeaderComponent should create the app" time="0.633" classname="HeaderComponent"/>
<testcase name="HeaderComponent Should test ngOnInit" time="0.645" classname="HeaderComponent"/>
<testcase name="HeaderComponent Should test signOut" time="0.618" classname="HeaderComponent"/>
<testcase name="HeaderComponent should test lightThemeClicked" time="0.106" classname="HeaderComponent"/>
<testcase name="ServiceComponent should create" time="0.007" classname="ServiceComponent"/>
......
<system-out>
<![CDATA[
]]>
</system-out>
<system-err/>
sonar.projectKey=
sonar.sources=
sonar.exclusions=**/*spec.ts,**/*guard.ts,**/*module.ts,**/*.html,**/*.scss,**/*intercept.ts,**/*config.ts,**/*utils.ts,**/*pipe.ts
sonar.coverage.inclusions=**/*component.ts,**/*service.ts
sonar.coverage.exclusions=**/*spec.ts,**/guard.ts,**/*.html,**/*module.ts,**/*.scss,**/*intercept.ts,**/*config.ts,**/*utils.ts,**/*pipe.ts
sonar.projectName=
sonar.sourceEncoding=UTF-8
sonar.projectversion=1.0.0
//I tried all below properties
sonar.testExecutionReportPaths=./junit-test.xml
sonar.genericcoverage.unitTestReportPaths=
sonar.genericcoverage.unitTestReportPaths=./junit-test.xml
sonar.test.ReportPaths="./junit-test.xml"
sonar.junit.reportPaths="./junit-test.xml"
sonar.javascript.jstestdriver.reportsPaths="./junit-test.xml"
sonar.javascript.lcov.reportPaths="./lcov.info"
Parsing /Jenkinshome/workspace/*/junit-test.xml
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 50.951s
INFO: Final Memory: 29M/107M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Error during parsing of generic test execution report '/Jenkinshome/workspace/*/junit-test.xml'. Look at the SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unknown XML node, expected "testExecutions" but got "testsuite" at line 2
ERROR:
===========
Can somebody guide on issue.
I want to generate report in below format as per sonar doc- Generic Test Data | SonarQube Docs
<testExecutions version="1">
<file path="testx/ClassOneTest.xoo">
<testCase name="test1" duration="5"/>
<skipped message="short message">other</skipped>
</testCase>
</file>
</testExecutions>
How can I do that?
I see coverage and other required details,except unit test count.