How to get Sonar to report both Java and JavaScript tests run by Maven - maven

Our project uses Maven as the build tool and we are using Sonar to track quality. JUnit tests are executed by SureFire and the results are displayed in Sonar. We've added some JavaScript tests which are run by the jasmine-maven-plugin and want to include these results in the Sonar project.
The plugin generates a JUnit style XML report. How should we go about including the XML report in Sonar? Do we want to merge the XML reports as part of the build maybe?

You need to be sure the format generated by Jasmine is compliant with the JUnit XML format expected by the JavaScript Plugin : http://docs.sonarqube.org/display/PLUG/JavaScript+Unit+Tests+Execution+Reports+Import
You can also have a look at the format supported by the Generic Test Coverage Plugin : http://docs.sonarqube.org/display/SONAR/Generic+Test+Coverage
You don't need to merge the XML reports, there are different sonar.* properties to feed depending on the way you want to load your data: thru the JavaScript Plugin or the Generic Test Coverage. As a consequence, you don't need to run SonarQube analysis twice.

Related

how to create jbehave report with jenkins pipeline?

i have some set of jbehave tests and regular jenkins job with xunit plugin that create report from xml files. So far so good. Now, unfortunately i need to add some actions and it is easier to add them in pipeline. But i don't get how to generate jbehave report in pipeline. Been trying to use 'pipeline-syntax' help but this page only generate xunit([<object of type org.jbehave.jenkins.JBehavePluginType>])

JaCoCo with multi-module Maven project - Only record coverage by module owned tests

We have a large Maven project with about 50 modules. Today we have a good setup where we get a combined JaCoCo coverage for the whole project. We also use the final binary generated by JaCoCo for custom coverage logic.
We would like to implement a more strict coverage policy where only tests in the same module contribute to the overall coverage. We want every module to be responsible for its own tests and coverage.
For example. Module A depends on module B. A has code that makes use of code in B. When tests in A is run, we do not want to have coverage from any class in B recorded.
Is this setup possible? Trying around, I find that JaCoCo has many options for filtering when generating the final report, but I'd like to do this in the first step, when the coverage is collected.
Eventually, I'd like to end up with a JaCoCo exec file in each module's target directory that only has classes recorded from its own module. It would be perfectly fine if we had to do some configuration on a module-by-module basis like having an explicit package expression for inclusion.
Trying around, I find that JaCoCo has many options for filtering when generating the final report, but I'd like to do this in the first step, when the coverage is collected.
There is also options for filtering during collection - see includes and excludes options of JaCoCo Java Agent and corresponding options of prepare-agent in jacoco-maven-plugin.
Build of JaCoCo itself uses them exactly for this.

jacoco code coverage on integration test cases without sources

I have collected jacoco code coverage on integration test cases. Now I want to upload integration code coverage in Sonar 6.3. Since these are integration coverage results, source code is not available. Is it possible to show integration code coverage results into Sonar by any api/any other methos. If it possible, please share the relevant documentation. It would help me a lot.
You cannot update an existing analysis. Your only option is to run the integration tests before analysis, and feed the report into the analysis.

How to check test quality with Sonar?

Currently, we are using Sonar to check the quality of our production code. I would Like to check the quality of the test Code either.
How can I do it ?
I tried to change the "sonar.sources" to include test, but in this case i have an error : test folders are defined twice, one in test and one in source.
May be I can configure sonar / maven / jenkins to run 2 analysis : first one, the src code, with the test coverage, thant the tests (only quality, no coverage). But I also need to have everything run in a single jenkins job and displayed in a single Sonar Project.
And I don't know where to configure (pom ? sonar ? jenkins ?) I found some things about profiles, but it seems to be deprecated for my version.
I'm using Sonar 5.1, run from a jenkins job.
our Sonar properties in the pom are :
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<run.addResources>false</run.addResources>
<sonar-maven-plugin.version>2.6</sonar-maven-plugin.version>
<sonar.exclusions>src/main/webapp/assets/**/*.*,
src/main/webapp/bower_components/**/*.*,
src/main/webapp/dist/**/*.*</sonar.exclusions>
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
<sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
<sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>
<sonar.sources>${project.basedir}/src/main/</sonar.sources>
<sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
In the latest versions of the Java plugin there are some rules to check tests, but they are test-specific rules. I.E. they check if your #Test methods contain assertions &etc. You simply need to add those rules to your profile.
If, however, you're talking about running "code rules" on your tests, then your best bet is probably to define another project where the tests are treated as sources. Since you've already noted the difficulties of doing that with Maven, I would use SonarQube Scanner for this separate, second analysis.

Reusing Karma generated Unit Test Report by SonarQube

I am using Karma Test Runner on my JavaScript project to generate a Unit Test Report (target/surefire-report/TESTS-karma.xml) but I am unable to make SonarQube import this by setting 'sonar.dynamicAnalysis' to 'reuseReports'.
I configured my Maven POM as follows:
<sonar.language>js</sonar.language>
<sonar.inclusions>app/**,astCommon/**</sonar.inclusions>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.javascript.jstest.reportsPath>target/surefire-reports</sonar.javascript.jstest.reportsPath>
<sonar.javascript.jstestdriver.reportsPath>target/surefire-reports</sonar.javascript.jstestdriver.reportsPath>
<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
<sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
(I guess "sonar.javascript.jstest.reportsPath" is the right property but just to be sure I did include some other properties as well)
What also surpises me is that I do not get a warning when I enter an incorrect path in 'sonar.javascript.jstest.reportsPath'. I kind of expected 'Reports path not found'. This makes me suspect that SonarQube somehow is not aware that it should reuse the existing report.
Any hint is appreciated.
Thanks and best,
Ronald

Resources