How to get code coverage in play 2.6.x - java

I tried to get code coverage as documented in the documentation:
Modules - Cobertura: https://www.playframework.com/modules/cobertura-2.4/home
But this documentation seems to be heavily out of date. Also all answers on this topic on stackoverflow are not working.
What is the way to get Java code coverage with play version 2.6.x?

I couldn't get cobertura to work with play but I'm using IntelliJ as IDE.
IntelliJ provides running unit test with coder coverage.
IntelliJ offers it's own code coverage tool, JaCoCo and Emma.
This seems to work well running the tests as normal unit tests.

Related

IntelliJ - Test coverage. Only show classes that is tested

I run a Unit test with coverage, and get the Coverage list.
The list contains the class that I am testing, and also classes that I have not tested. See picture below.
Is it a way to automatically hide classes that is not tested?
At the moment of writing this answer (Intellij Idea 2019.3 and Bundled Coverage Plugin), there is no such option.
Below are the only available configurations of Coverage Plugin.

Is there a plugin or tool which I can use to generate coverage from running application without testcases?

I have a Java based web application which have few ReST endpoints exposed. I want to check the code coverage in running VM. Is there any tool or plugin I can use for this purpose?
I tried looking into jacoco but It looks like it provides code coverage only if you have configured unit/integration tests.
Sometimes, it becomes very difficult to write testcases for all possible scenarios. So, is there a way I can get code coverage without test cases?
Thanks a ton in advance. :)
After doing more search on internet, I have found a very good link which fulfill my requirements:
https://automationrhapsody.com/code-coverage-of-manual-or-automated-tests-with-jacoco/
In short, follow below steps to generate code coverage report without testcases:
Install Jacoco Eclipse plugin: EclEmma Java Code Coverage
Download jacocoagent.jar and put it some location on your computer e.g.
C:\JoCoCo\jacocoagent.jar
Run your application with this VM arguments: -
javaagent:C:\JaCoCo\jacocoagent.jar=output=tcpserver
Import coverage reports:File -> Import -> Coverage Session -> select Agent
address radio button but leave defaults -> enter some name and select code
under test.

Configure Sonar 6.2 code coverage on a Maven project

I have pretty standard Maven multi-modules project (with JUnit, Arquillian and Selenium tests). I have Sonar 6.2 installed on a server. And on my project on Sonar the Code Coverage metric indicates 0.0%. But I know it's wrong as I do have some test coverage.
I found this Generic Test Data documentation page that explains that since 6.2 Sonar is supporting code coverage out of the box and that I have to pass a comma-delimited list of report paths to a parameter sonar.coverageReportPaths (I guess provided either in my pom or in command line).
I'm fine with that. But I cannot find out an example on how to setup this for a pretty classical Java project. What kind of file do I need to give in the list ? The relative paths to each of my Surefire/Failsafe reports ? Do I need to generate Jacoco reports in addition ? Can I give a "generic" path like report.xml if all of my reports have the same name ?
For standard Java project is it probably the easiest to use JaCoCo to generate coverage data and then feed it to SonarJava (SonarQube's plugin to analyze Java code). You can find documentation here
https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project
You might find mentions of separation between unit tests and integration tests, this has been deprecated and now there is only single kind of coverage.
Don't hesitate to reach out to mailing list or ask question if something is not clear, we are in the process of improving this documentation.

How to set up Jacoco code coverage tool in Eclipse for viewing colors in Java code?

I have setup jacoco in jenkins as part of functional test job to generate code coverage report. But I feel its very tough to understand.
Somewhere I read that covered and uncovered lines of code are shown in colors in Eclipse. This is for functional tests which connect to a stage where the whole business logic has been deployed. This is present inside Eclipse also as part of the project. How to set it up?
What difference the setup has for unit tests?
You can download the Eclemma plugin from Eclipse marketplace.
Open Marketplace from Help menu.
Search for Eclemma Java Code Coverage.
Install and Restart Eclipse.
Right-Click on the project, select Coverage as -> JUnit Test
http://www.eclemma.org/userdoc/importexport.html mentions being able to import reports, but that they have to be exactly the same class files both when the report was generated and within the Eclipse workspace. It may work, it may not.

How to test the code coverage of a java web application in netbeans?

I have a java web application and I use Netbeans6.9.1 to develop it.
I wrote some Junit test class of some DAO classes, but I failed to run code coverage test.
It seems NetBeans Code Coverage Plugin does not support java web application
code coverage,
and I can not activate coverage collection as the Tutorial.
Any ideas?
If you're writing unit tests of DAOs, none of the code will run on the app server yet (since the DAOs should be instantiated in the same JVM as the test class), so you should be able to do code coverage. What exact errors are you getting?
Cobertura is a good code coverage tool, and there's a plugin for NetBeans, too.
I can confirm that the Codecoverage plug-in works in Netbeans 7.2.
However in web projects the Coverage menu option is NOT active :-(

Categories

Resources