Verify jacoco covarage tests using power mockito without mvn command - java

Is there a way to verify the coverage of jacoco in eclipse without run mvn test command? I'm using power mock, so Eclemma does not work in my case.

Try a plugin e.g. EclEmma
https://www.eclemma.org/
Fast develop/test cycle: Launches from within the workbench like JUnit test runs can directly be analyzed for code coverage.
Rich coverage analysis: Coverage results are immediately summarized and highlighted in the Java source code editors.
Non-invasive: EclEmma does not require modifying your projects or performing any other setup.

Related

Generate separate coverage reports for tests using Jacoco or IntelliJ IDEA

I have a Java application set up on IntelliJ IDEA. I have several tests for which I need to generate coverage reports individually for each of the tests.
IntelliJ IDEA coverage runner runs all the tests at once and generates a single report showing the overall coverage. How can I use IntelliJ IDEA coverage runner or Jacoco plugin in gradle script to generate separate reports the tests?
Run tests separately one by one (see How to run only one test class on gradle), for each run use separate directory to save report.

Getting Integration tests code coverage of java project built using TestNG

I wanted to get code coverage of regression tests,which tests java webserver endpoints.
Things I have
1. I am having jar file of source
2. Regression code written using TestNG framework.
So here, I will run this jar file to run webserver and then I will run my regression code which will test running webserver.Here I wanted to get code coverage report of Regression tests.Can anyone give any suggestion ?
You can use EMMA(A free code coverage tool). If you are using eclipse you can directly get it from market place. Also it supports running individual Java class file or jar file. Here is the link for more information.
http://emma.sourceforge.net/intro.html
If you're using Maven, you can have a look at qualinsight-maven-cobertura-mojo. There is a companion Github project that provides examples showing how to use it along with jetty (versions 7.6.x, 8.1.x, 9.2.x, 9.3.x). In the exmaples JUnit is being used, but it has no impact at all on the result, you can use TestNG if you want to.
The example shows how to use this Maven plugin and configure your project in order to:
Instrument your code for coverage with qualinsight-maven-mojo-core
run your Jetty server and deploy instrumented code
run your tests (you'll have to replace Junit tests by TestNG ones, and make sure they are run during the integration-test phase)
stop your Jetty server (this will dump coverage file to disk)
Generate coverage report
If needed coverage reports can then be imported in SonarQube using the Generic Coverage plugin (see documentation.)
Note that this plugin has some advantages and limitations compared to cobertura-maven-plugin (see its documentation), but given the description of your requirements, none of the limitations seems to be a blocker in your context.

Sonar Java - Is there a way to enforce unit test coverage?

Currently I have Sonar setup to show unit test coverage which works great. Is there a way to enforce a certain percentage of unit test coverage for a project? For example if the coverage drops below 50%, I want it to be a sonar violation and for my build to fail.
Yes, it is possible. For example, if you use jenkins, you can configure and step in which you can choose the minimum coverage(JaCoCo Plugin).
In the jenkins job, you can pass the unit test, and take the coverage report of jacoco, and then, a step with the sonar plugin, but if the coverage is less than for instance 50%, the jenkins will show your build as failure.
You need to install this plugin Build Breaker the only purpose of this plugin is to break the build when new alerts raise in the analysis.

Is there an equivalent of junit test suite in Scala

In Java, you can create a junit test suites and put all your junit test cases in it. This allows you to run all your test cases all at once and get the testing results immediately (e.g. how many tests passsed and failed, and which tests failed). Is there something equivalent in Scala within the ScalaTest?
Thanks
I don't know if there's anything equivalent for ScalaTest but in general this is a bad idea. It requires you to keep your test suite class up to date when you add new tests. Both your IDE and your build tool should let you be able to automatically discover and run all tests at once.
If you're using maven or gradle, just placing all your tests under the src/test/scala directory should be enough that running the test target will execute all test

Sonar how to run unit test successfully

I have a project built with maven and I recently integrated Sonar... It is really easy to configure Sonar to analyze you're project but I couldn't configure it to run my project unit test also. I tried something with Jacoco but I get some Seam error and all the other tests are skipped. By the way I'm using TestNG to run tests manually.
You can use the relevant Analysis Parameters of sonar to reuse the test reports from your earlier run. You would set sonar.dynamicAnalysis property to reuseReports and specify the location of the reports in sonar.jacoco.reportPath or sonar.surefire.reportPath based on how you run the tests.
By the way, mvn sonar:sonar invokes maven's test goal, which runs unit tests as part of the analysis. So ideally if your maven can run unit tests, sonar should be able to run them.
Sonar cannot run tests, it can only analyze testing reports.
You can run yourself JUnit ( using Maven or Ant for exemple ) and push reports to Sonar (try Sonar's Maven plugin for that)
or you can give yourself a build factory (try hudson for exemple) and plug it to sonar.

Categories