SimpleCov reporting 100% coverage when merging result - ruby

I have a ruby project that contains many subprojects. Each subproject runs simplecov and the root project folder runs a rakefile to generate the total coverage report for all the subprojects. The problem is that it shows the correct coverage for the last run and all the others before that are shown as a 100%. Does anyone know how to fix this?
subproject coverage (/root/plugin1/tests/plugin/test.rb):
SimpleCov.start do
coverage_dir "#{ENV['WORKSPACE']}/coverage"
command_name 'plugin1'
root "#{ENV['WORKSPACE']}"
at_exit do
SimpleCov.result
end
end
In the root rakefile (/root/):
SimpleCov.coverage_dir "#{ENV['WORKSPACE']}/coverage"
task :coverage do
SimpleCov.result.format!
end
it creates a coverage folder in root (/root/coverage).
I followed this from: https://github.com/colszowka/simplecov/issues/147

Related

Sonarqube exclude files that doesn't match a rule on code coverage

I have several packages inside my project, inside each I have something like:
- MyClass.java
- MyClassDAO.java
- MyClassResource.java
I want to exclude only MyClass from sonar code coverage, is it possible?

Skip simplecov summary when there are test failures

I have a requirement,
Simplecov should print this line
Coverage report generated ...
only if the test suite is green.
Is this possible?
Here's my initializer
SimpleCov.start do
add_filter "/test/"
coverage_dir "/tmp/coverage/"
end
There is a at_exit hook in SimpleCov where you can skip the message
SimpleCov.at_exit do
SimpleCov.result.format! if all_test_passed
end
but could not find a workaround for 'all_test_passed'. Did not find a way to get summary so that i can check if all tests passed.

How to generate the code coverage report using jacoco where source code and tests are in different projects?

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

How do I get subproject jars into my zip?

I'm trying to make a top-level zip in my buildr buildfile, but the jar files don't seem to end up in the resulting zip.
The project structure has sub-projects:
desc 'Main project'
define 'hex' do
#... omitting top-level config ...
desc 'Hex Utilities'
define 'util' do
package :jar
end
#... omitting other sub-projects, they're all the same ...
binaries_id = "#{id}-components-#{version}"
package(:zip, :file => _("target/#{binaries_id}.zip")).path(binaries_id).tap do |path|
path.include 'COPYING', 'COPYING.LESSER', 'CHANGELOG', 'README.markdown'
%w{anno binary interpreter util viewer}.each do |proj|
path.include project(proj).packages
end
end
end
I have also tried:
path.include project(proj).package(:jar)
explicitly selecting only the jar, though it's the only package anyway, and also:
path.include project(proj).packages.map{|p| "#{p}"}
which maps them to strings, since I noticed all the other path.include lines take strings and suspected that it simply might not work with arrays of package objects, but this doesn't work either. Then my last thought was to just jam in the strings like what I am doing with the rest of the includes:
path.include "#{proj}/target/hex-#{proj}-#{version}.jar"
But even this doesn't work, so I have no idea how to proceed.
I can not seem to reproduce the behaviour. With the most recent release of buildr I created a buildfile that looks like
define 'foo' do
project.version = '1.0'
define 'bar' do
package :jar
end
package(:zip, :file => _("somepath.zip")).path('somepath').tap do |path|
path.include project('bar').packages
end
end
Run "buildr clean package" and then "unzip -t somepath.zip" produces;
Archive: somepath.zip
testing: somepath/ OK
testing: somepath/foo-bar-1.0.jar OK
No errors detected in compressed data of somepath.zip.
Which is what I would expect.

project name in gradle must be a directory?

Is it mandatory to have a directory with same name as project in gradle ? My code is like this:
.
|-- build.gradle
`-- suites
`-- lrgabc.gradle
1 directory, 2 files
content of suites/lrgabc.gradle
$ cat suites/lrgabc.gradle
project(':lrgabc') {
task block1 << {
println "Hello from lrgabc.block1"
}
}
Content of build.gradle
apply from: 'suites/lrgabc.gradle'
When I run, gradle -q :lrgabc:block1 I get
* Where:
Script '/home/skgupta/gradle-examples/multiproject/suites/lrgabc.gradle' line: 1
* What went wrong:
A problem occurred evaluating script.
> Project with path ':lrgabc' could not be found in root project 'multiproject'.
Is it mandatory to have 'lrgabc' as a directory under 'multiproject' ?
What I'm trying is under one single project, create multiple test suites using gradle. Each test suite is one gradle file, where each task in that gradle represent one test [These are non java tests, like perl, python..etc]
How do I solve this ?
Each subproject in a multi-project Gradle build needs to have a separate project directory. However, directory names do not have to correspond to project names (this is configurable in settings.gradle).
You really want to take a look at the documentation for multi-project builds - http://www.gradle.org/docs/current/userguide/multi_project_builds.html There are also samples in Gradle distribution that can help you.
You don't need to create new projects to create more test tasks. You can have these tests in one project. It is quite common to define multiple test suite like unit and functional tests this way. http://blog.safaribooksonline.com/2013/08/22/gradle-test-organization/ shows a possible implementation.

Resources