JaCoCo Functional Test Coverage on SONAR - maven

I am working on to get Functional Test Coverage using JaCoCo and SONAR for a java based application.
My Requirement:
Get Functional Test Coverage.
Publish the Functional Test Coverage results to SONAR(pass on the jacoco.exec file to SONAR)
Below is the set up I did:
Set up instances on my DVL(development box) and make the system up and running.
In the /bin directory of the instances, I am including jacoco agent in the CATALINA_OPTS variable with below configuration:
vim catalina.sh
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:${XYZ_ROOT}/WEB-INF/lib/org.jacoco.agent-0.5.8.201206210517.jar=includes=com.xyz.xx.*,excludes=com.xyz.xx.webclient.command.UIBean,output=tcpclient,address=lxdm379m7.xyz.com,port=9000"
(lxdm379m7.xyz.com is my sonar server and 9000 is the port number)
Now restarted the server, And the server is up.
I do manual testing on my AUT which is on my DVL. Hit pages back and forth.
My Issue:
Not able to generate the jacoco.exec file.
Help I need:
Why is the jacoco.exec file not generated.
If it is generated, where can I find it? and how to pass it on to SONAR ?
Any help or clue on this is appreciated.

Related

SonarQube with mixed unit tests files and source files

We've had trouble setting up a custom SonarQube server. The global analysis works fine, but unit test files are being analyzed and they trigger issues on the report.
For instance, we have hardcoded IP addresses in unit test files, and Sonar reports a security hotspot.
The arborescence is as follow:
component-a
module1/src/...
module1/tests/...
module2/src/...
module2/tests/...
component-b
src/...
tests/...
component-c
src/...
tests/...
I've tried the following parameters but it does not work, as test files are still being analyzed:
sonar.sources=.
sonar.sources.inclusions=component-a/**/src,component-b/src,component-c/src
sonar.sources.exclusions=component-a/**/tests,component-b/tests,component-c/tests
sonar.tests=.
sonar.test.inclusions=component-a/**/tests,component-b/tests,component-c/tests
Do you have any idea on how to make this configuration work?
Thanks in advance
Try something like:
sonar.sources=.
sonar.tests=.
sonar.test.inclusions=**/tests/**/*
The test files should still be analyzed but only as test files (security hotspots should not be reported on them).

Jacoco Session created Exed shows no Coverage on Sonarqube

I created a Exec via JacocoAgent on my Local machine (For IT-Testing). Now when I try to upload this Exec to sonarqube, it shows no Coverage.
I built an Ant Task which created an html Report and there I saw, that there was definetely coverage generated. I saw it also in the Jacoco Plugin for Eclipse.
Any Suggestions ?
To execute Sonaranalysis I use Gradle with the "sonar.jacoco.reportpaths" property.
The Log says it is able to read the file (I tried it with the exec, which was generated by Unit Tests and it worked)

Failed to publish TestNG Report in Jenkins

I have used Maven project with Selenium & TestNG to create automated scripts which I want to execute from Jenkins. In Jenkins I have added the TestNG plugin to publish the TestNG report. But it is not getting displayed. I'm getting the below mentioned error.
Error:
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: /target/surefire-reports/testng-results.xml
Did not find any matching files.
Finished: SUCCESS
Actual path of the TestNG report file:
E:\STUDY_MATERIAL\JAVA\WORKSPACE\SeleneniumFrameWork\target\surefire-reports\testng-results.xml
I have tried the following options but didn't work out for me.
Tried giving the full path of the TestNG report. Forward ans backward slash in the pattern.
I have tried different other options by changing the TestNG result file path but it's working for me.
Please share some inputs on how to resolve this issue.
"testng-results.xml" file is available in workspace. But it's failed to display the report. I have attached screenshot of Jenkins workspace and Console Output.
Note: I am using Jenkins 2.7.0 in Windows 10.
Jenkins Workspace
I have attached the Job configuration details of Jenkins.
Job Configuration Details
Few checkpoints :
1. Check if testng is producing this file at the specified location : /target/surefire-reports/testng-results.xml
2. TestNG needs to be configured to generate xml report
If this file is there, pass path in file locator as :
target/surefire-reports/testng-results.xml
Hopefully, you will get results on jenkins if everything mentioned above is correct.

JavaScript Unit Tests not working on SonarQube

I have below problems with SonarRunner.
SonarQube along with Sonar runner unable to pull junit format xml reports
Unit Tests or Test Coverage widget doesn't show up. It says No Data.
I am following instructions described here
I manually created report file in XML format as described, but still no luck.
Below is the XML file - TEST-Firefox_210_Mac_OS.com.company.BarTest.xml,
<testsuite name="Firefox_210_Mac_OS.com.company.BarTest" errors="0" failures="0" tests="3" time="0.0">
<testcase classname="Firefox_210_Mac_OS.com.company.BarTest" name="testfullName" time="0.0"/>
</testsuite>
To pull the Unit Test execution report to show on sonar dashboard. I have used sample git project from here
and below is my sonar-project.properties,
# project metadata (required)
sonar.projectKey=org.codehaus.sonar:javascript-sonar-runner-jstestdriver
sonar.projectName=JavaScript project with Sonar Runner reusing reports generated by JsTestDriver
sonar.projectVersion=1.0
# path to source directories (required)
sonar.sources=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources
# path to tests source directories (required)
sonar.tests=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests
sonar.javascript.jstestdriver.reportsPath=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/target/TEST-Firefox_210_Mac_OS.com.company.BarTest.xml
sonar.sourceEncoding=UTF-8
below is my jsTestDriver.conf
server: http://localhost:9876
load:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/com/company/*.js
test:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/com/company/*.js
plugin:
- name: "coverage"
jar: "coverage-1.3.5.jar"
module: "com.google.jstestdriver.coverage.CoverageModule"
My sonarqube is running on port : 9000 and below is the screen shot. As you see SonarRunner and jsTestDriver just doing a code analysis and not showing any unit tests.
SonarQube doc website says jsTestDriver will run the javascript unit
tests and copy the results in target folder in XML format
SonarQube doesnt run your Unit Tests, it just gathers the reports generated from your manuall run or other tools automatic run (like: Jenkins).
From SonarQube doc:
Prior to the SonarQube analysis, execute your unit tests in order to
generate XML report. The JUnit like XML format supported is the one
generated by js-test-driver
Then I manually created report file in XML format as described, but
still no luck.
If you created manually the report files and reports are still not showing, check your paths if ok.Check if sonar is really reading data from C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/ path

set configuration properties in sonar

Maybe, this question is silly but I'm very new. I try to search without luck.
I got two errors when building maven project with sonar:
No information about coverage per test.
Although I had test code and these testing classes cover the code.
The global property 'sonar.doxygen.deploymentPath' is not set. Set it in SONAR and run another analysis.
I dont know it should be set where in sonar server. I set in web.xml or sonar-server.properties but it does not work.
Thanks.
About the first warning message this is not an error but a warning : since Sonar 3.5 this is possible to get the code coverage relating to each unit test. Here the message just says that this feature is not activated which is expected by default. Nevertheless I do agree that this warning message can be misleading.
About the second error message, I don't know the doxygen plugin but the message seems to be pretty clear : the sonar.doxygen.deploymentPath property has not be defined. See the plugin documentation : http://docs.codehaus.org/display/SONAR/Doxygen+Plugin.
Two things:
There is no war folder anymore since the sonarqube has given up tomcat support
The doxygen plugin is not implemented to upload the files in to the sonarqube server &/ installation, which means it only can be done by referencing the path inside your installation, e.g.:
run "mvn install sonar:sonar" in your project "/root/test.example.sonar.com"
in sonarqube set the cfg-key "sonar.doxygen.deploymentPath" the value: "/root/sonarqube-4.1.1/web/" and the cfg-key "sonar.doxygen.deploymentUrl" the value: "http://:9000"
have fun with your doxygen
Remember that the plugin will only be run through your mvn cmd, refreshing the page only will not do the job, you will have to analyse again after each cfg set :/
Check the file system and folder permission

Resources