No code coverage Sonar with powermock - unit-testing

I have written a test case using powermock and easymock. I have sonarlint plugin associated with local sonarqube server. When i run sonarlint analysis on my test case no coverage is being shown. I know powermock disables eclemma coverage. Is this the same issue with sonarlint plugin too? Is there a way I can see unit test case coverage?

Related

PowerMockito whenNew without PrepareForTest

Jacoco does not cover tests using #PrepareForTest(Class.class).
I need to use PowerMockito whenNew method, but it does not work without the PrepareForTest annotation.
Is there any workaround for this issue?
JaCoCo could work in two mods:
collecting coverage with java agent
offline instrumentation
If you'd like to collect coverage from PowerMock test then you should use offline instrumentation.
Here working example for Gradle: https://github.com/SurpSG/jacoco-offline-instrumentation

Azure DevOps 'Run Only Impact Tests' doesn't work with XUnit Tests?

I have an ASP.net Web API project (.NET Framework v4.6.2) where I have written unit test cases using XUnit.
I have created a build pipeline in Azure DevOps with 'Run only impacted tests' set to checked. Also, my Visual Studio test version is set to *2.** in my test assemblies.
I have tried to run my mock tests (No data driven test cases) to check that only impacted test run but all the tests run.
I had hard luck finding the solution for It. Can anyone know how to do it right?
I have read this article and and done setting accordingly, but failed.

How do I clear a reported TeamCity service message build statistic?

I have a build configuration that is running code coverage on unit tests using TeamCity's built-in dotCover tool. Then another runner runs code coverage on some API tests using a non-supported tool. I am currently reporting the coverage stats to TeamCity using the service messages:
Write-Host "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='$totalLines']"
Write-Host "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='$totalLinesCovered']"
Everything works great. However, the first runner reports other statistics (Methods, Classes, Branches) on the unit tests and coverage it ran that I want cleared (I don't want any stats from the unit tests). How do I clear a build statistic that is already reported?
I tried using a similar message as above and setting value='' or value='0'. The value='' threw an java error that it couldn't parse, while value='0' had no effect on removing the statistic.
How do I clear a build statistic? Or just make dotCover not report any code-coverage stats?

Test coverage with jacoco, maven and sonar

I have more of a theoretical question. We have a project with complicated module hierarchy. The goal is to measure unit test coverage and in the future also integration test coverage.
In order to properly place the testing dependancies, plugins and configurations in the different project poms, I need to understand the interplay between the following plugins:
failsafe
surefire
jacoco
What I know is, failsafe generates integration test reports, surefire generates the unit tests reports and jacoco can use both to generate the test coverage report.
What I need to know is:
How jacoco interacts with both failsafe and surefire?
Do jacoco need failsafe and surefire?
Can you explain the jacoco configuration and particularly why does the problem with the argLine occur?
I found a lot of examples scattered, and got the jacoco plugin working, but my goal is to place all configs etc. where they are actually needed, so that they do not pollute the maven dependency-hierarchy.

Unit Test Coverage not displaying on Sonarqube - Running through Jenkins Sonar plugin - Test Success displays correctly

I am currently using jenkins to build a list of different modules for my project. I trigger the builds using Maven. I have sonarqube installed on the server and have set it up correctly so that when a module builds it is displayed on sonarqube and includes all of the basic details such as lines of code, technical debt etc. The modules all have Junit tests that run against them, and sonarqube displays this by saying that the Unit Test Sucess is 100% and it also says the number of tests that have been run in that module. However I cannot get the Unit tests coverage field to display anything and it is blank for all of the modules.
Here is an exert (one module) from my pom.xml
customer.sonar.projectBaseDir=.
customer.sonar.sources=D:/TFS/WorkSpace/DEV_2_HYBRID/APP_FO/application/customer/src/main/java
customer.sonar.Hybrid=Customer
customer.sonar.tests=D:/TFS/WorkSpace/DEV_2_HYBRID/APP_FO/application/customer/target/surefire-reports
customer.sonar.junit.reportsPath=D:/TFS/WorkSpace/DEV_2_HYBRID/APP_FO/application/customer/target/surefire-reports
The versions of the software I am using are as follows:
Sonarqube v.5.0,
Jenkins Sonarqube plugin v.2.1,
Maven v3.2.5
As I said at the beginning the unit test success rate does show successfully, so I believe it is only a small change needed that will get the unit test coverage field working.
Any help would be really appreciated!
You need to execute the coverage engine of your choice and provide the report to SonarQube via the appropriate property.
If you are using JaCoCo, the report importer is embeded in the java plugin, for other coverage engine (clover, cobertura...) you have to install the dedicated plugin.
For more information see the dedicated page of documentation.