I have several tests generating coverage reports with istanbul. One of them is generated by karma-coverage plugin. I am merging these reports with istanbul report but files from karma-coverage report are not included in the merged report.
There was an issue with file paths that had the same symptoms but it seems to have been fixed: https://github.com/karma-runner/karma-coverage/pull/163
So it is probably something else.
I have tried using grunt-istanbul that instruments source files separately and then I browserify them in the bundle. I also tried using preprocessor from karma-coverage plugin to instrument the bundle. In both cases karma-coverage generates reports that look ok, but in both cases these reports are not included in the merged report.
What am I doing wrongly here? Is there some workaround maybe?
Package versions:
"karma": "^0.13.10",
"karma-coverage": "^0.5.2",
"grunt-istanbul": "^0.6.1"
karma.conf.js
reporters: ['coverage', 'spec'],
coverageReporter: {
type: 'lcov',
dir: 'coverage'
}
Coverage reporter should have type: 'lcov' - then you can merge reports
If you are able to generate coverage separately then you can merge them as specified here:
link
Related
I have a maven project and the below step is mentioned right after executing surefire tests(for JUnit) and failsafe (for Integration tests). However, I am not able to exclude the files from generated-sources folder. However, if I use a single exclusionPattern:'/tomcat/', it is excluding tomcat folder from the report
I have tried below option:
**```
post {
always {
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/*.xml'
step( [ $class: 'JacocoPublisher', exclusionPattern: '**/target/generated-sources/**,**/tomcat/**'] )
}
}
```**
but it is only excluding the tomcat folders and not the generated-sources. Still seeing files from this folder in coverage report.
As a workaround, I am targeting the java packages inside target directory to improve coverage. It's not a very efficient way to do it as I had to add entries for multiple packages inside exclusionPattern. But, it works well for my requirement.
I’m using JaCoCo Gradle plugin in my project.
Just as an example of the question, most of my code is under package com.me.mysoftware.
I’m using code generator that generate classes under build/generated/java/....../com/me/software/MyGeneratedClass.java
I would like that all of the classes under this generated directory will be excluded from JaCoCo report, but not the entire package (what’s under src/main/...)
How is this possible?
add excludes = [ com.me.software.MyGeneratedClass ]
see https://docs.gradle.org/current/userguide/jacoco_plugin.html#default_values_of_the_jacoco_task_extension for more help
I am using gometalinterv2 in my Go project for linting. After the lint report is generated, the report file is linked to sonarqube for analysis and presentation.
I want to exclude some files like *_test.go from linting. I know there is a --exclude flag for gometalinterv2 to exclude folders. But since _test.go files are in the same folder/package as the source code, this won't work.
So is there any way to achieve this (either at linting stage or in sonar properties file)?
Add config file .gometalinter.json to the root of your project and specify rules for excluding:
{
"exclude": [
".*_test.go",
"/any/folder/"
]
}
I found another way after I marked #bayrinet's answer. The files (not just folders) to be excluded can also be passed to the command using the exclude flag like below -
>gometalinter.v2 ./... --exclude=somefolder --exclude=.*_test.go
I have a maven java project in some folder (it has some unit tests), and tests for the same code in another different project (different directory). Both source code and test share the same parent pom. Now I want to generate the code coverage report using JaCoCo.
How to instrument sources? How to run tests on instrumented code? And how to integrate and get the result report?
Say Project ABC contains the code and project XYZ contains the test cases.
Note:
Project ABC and Project XYZ are independent projects
Both ABC and XYZ contains multiple sub projects(Need to integrate everything).
I had a similar problem. I found a solution by changing the path of the jacoco report path:
<sonar.surefire.reportsPath>${project.basedir}/../target/surefire-reports</sonar.surefire.reportsPath>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
I added these properties and configured the jacoco plugin to append reports and not overwrite them by:
<configuration>
<append>true</append>
</configuration>
This way jacoco write the reports to the base directory of the multi module project. The sonar plugin finds these and analyses them.
I had a problem when building a "reference application" with multiple sub-modules and trying to generate test coverage for the sub-modules and have them push to sonarqube. The issue I was having was that since the sub-modules referenced each other, the resulting jacoco reports were getting overwritten and I'd end up with results for a single module. This may not be the same issue as posted above, but I did solve it by using "append" in gradle, so just want to show how to do that.
In the build.gradle file for each module, I have:
testOptions {
unitTests.returnDefaultValues = true
unitTests.includeAndroidResources = true
unitTests.all {
jacoco {
append = true
includeNoLocationClasses = true
}
systemProperty 'robolectric.enabledSdks', '28'
}
}
s
I'm using:
Sonar version: 2.10
Emma version: 2.1.5320
Sonar Emma plugin version: 1.2
I'm able to generate an Emma report showing coverage of the tests themselves (ideally this would be 100% but in practice it's not always), but Sonar shows only the coverage of the src files. How do I get it to show the coverage of the test files, too?
Would switching to Cobertura help?
AFAICT from:
public final class NewCoverageFileAnalyzer {
public boolean shouldDecorate(Resource resource) {
return Scopes.isFile(resource) && !Qualifiers.UNIT_TEST_FILE.equals(resource.getQualifier());
}
}
it looks like coverage of test files can't be shown in Sonar without changing the Sonar code.
Comment:
Counting test classes as coverage might inflate coverage ratio.
Using more test files would allow coverage > 100 % (lines covered / lines of production code).
It might still be usefull to see, if there is some dead test code somewhere.