Get jacoco report from running acceptance test on real application - spring-boot

I'm new to sonar and jacoco and I wasn't able to find an ansewer to following question
We are going to use sonar and jacoco to analyze our test coverage.
We are going to have three kind of test: unit test, integration test (use spring boot test) and acceptance test that we will run on real application instance. We want to merge test results. To generating jacoco files for unit and integration tests is not a problem as they have access to source code. And we can merge this reports in sonar.
My question is it possible to generate jacoco file for acceptance test which interacts with real application? And maybe you will have a link to how to do it?
My best idea for now is to run acceptance tests twice on both real application and embedded one, and get report from embedded. But maybe there is better solution.
Thanks,

JaCoCo is able to record any kind of execution of Java application - you just need to start this application with agent, for example:
java -javaagent:jacoco-0.8.0/lib/jacocoagent.jar -cp classes Main
By default at termination of application this will produce file jacoco.exec with execution data. There are also ways to get execution data from running application.
And there are plenty of examples all over the internet of using agent in various cases - with Spring Boot, Tomcat, Weblogic, etc.
After that report can be generated using this execution data jacoco.exec and exactly the same class files that were used at runtime for generation of execution data. For example using JaCoCo command line interface (there are also Ant tasks, Gradle plugin, Maven plugin):
java -jar jacoco-0.8.0/lib/jacococli.jar \
report \
jacoco.exec \
--classfiles classes \
--html report
Report can be generated without source files, but in this case you won't be able to drill down lower than method level granularity:
Report with source files:
jacoco-0.8.0/lib/jacococli.jar \
report \
jacoco.exec \
--classfiles classes \
--html report \
--sourcefiles src
Now about SonarQube: it performs analysis of exec and class files, and so also requires that class files are the same as where used at runtime for generation of exec file. So you need to guarantee that SonarQube analysis is performed for exactly the same class files as under testing.

Related

Disable Integration test case using gradle command in springboot

I am using POSTGRES SQL as DB for my springboot application .Sonarqube integration test cases fail as SonarQube is unable to connect to DB.How can i disable my integration test cases using gradlew command during Jenkins build ?
Below is link where i have shown my code in detail SonarQube does not calculate code coverage
You would likely have to have some kind of naming convention for the tests you wish to exclude. Then, you can readily exclude them using something like the following:
In your build.gradle file, add:
test {
if (project.hasProperty('excludeTests')) {
exclude project.property('excludeTests')
}
}
From the command line:
gradle test -PexcludeTests=**/Integration*

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)

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

JaCoCo Functional Test Coverage on SONAR

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.

How to get code coverage for tests run using QF test tool

I use QF test tool (http://www.qfs.de/en/qftest/) to run my integrated UI based tests . Is there any tool which can get code coverage of qft test suites ?
Note : I use Sonar (jacoco plugin) to get code coverage for Junit tests .
I googled a lot and couldn't find any relevant documentation for this . So any links to documentation or example would be helpfull
oYes, this is possible. I'm using QF-Test with Jenkins CI, Sonar and JaCoCo.
To keep it short, in QF-Test go to the step which invokes the SUT and add the -javaagent: parameter to the program
e.g.:
-javaagent:/path/to/mvnlib/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=/usr/share/tomcat6/.jenkins/jobs/Integration_Build/workspace/your.program.test/jacoco/jacoco-qf.exec,includes=your.packages.*,output=file
Configure Jenkins (with Jacoco Plugin) to look for jacoco-qf.exec file.
PS: If you use regular Junit Tests you should combine both the coverage of QF-Test and Junit by this Ant script:
<jacoco:merge destfile="${jacoco.file}">
    <fileset dir="${jacoco.report.dir}" includes="*.exec"/>
</jacoco:merge>

Resources