How to use Cobertura to test the coverage of benchmark Dacapo? - cobertura

Recently, I was using a new benchmark: Dacapo(Here is the website:http://dacapobench.org/).
My teacher told me to use the Cobertura to test the branch coverage of 11 benchmarks in Dacapo. Meanwhile, I was learning Cobertura. I found that Cobertura instruments .class file and then running them to get some reports. While Dacapo is a .jar file combines many files in it. I just do not know how to test them with Cobertura.
It will appreciated if you can provide some useful advice. Thanks!

Cobertura can instrument jar files if you use ant:
You can also pass in jar files to be instrumented using standard ant
filesets. Cobertura will extract each class from the jar and
instrument it. If 'todir' was not specified then the original jar will
be overwritten with an instrumented version. Otherwise a new jar will
be written to the output directory.
<cobertura-instrument todir="${instrumented.dir}">
<fileset dir="${jars.dir}">
<include name="my-simple-plugin.jar" />
</fileset>
</cobertura-instrument>

Related

Azure devops issue with sonar cloud code coverage

In azure devops build pipeline, I am having the below stages.
Prepare analysis on sonar cloud
dotnet restore
dotnet build
dotnet test
dontnet publish
copy test files .. this for copying (*.trx *.xml) to respective directory.
Run code analysis
Publish quality gate result.
here my pipeline runs successfully with the tests but its not giving code coverage. code coverage showing 0.00%
*.trx file is copying on the required path & I have also tried with the default path of trx file but its giving below message in logs.
ERROR MESSAGE
Post-processing started.
00:23:49.775 Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders.
00:23:49.995 Did not find any binary coverage files in the expected location.
00:23:49.995 Falling back on locating coverage files in the agent temp directory.
00:23:49.995 Searching for coverage files in D:\a\_temp
00:23:49.995 No coverage files found in the agent temp directory.
WARNING: The following projects do not have a valid ProjectGuid and were
not built using a valid solution (.sln) thus will be skipped from
analysis...
D:\a\1\s\Rost.API.Tests\Rost.API.Tests.csproj
I expect the code coverage in the pipeline, currently code coverage showing 0.00%.
May i confirm several questions with you?
Did you add --collect "Code coverage" option to the command line arguments?
Code coverage can be collected by adding --collect "Code coverage"
option to the command line arguments. This is currently only available
on the Windows platform.
If run the test command on local, did the code coverage show correctly?
BTW, SonarQube requires a valid Project GUID but Core projects dont actually use this.It is recommended to add the ProjectGUID in the test project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- SonarQube requires a valid Project GUID but Core projects dont actually use this -->
<ProjectGuid>{9C99E491-F56E-4515-9F0B-D72A5207DB13}</ProjectGuid>
</PropertyGroup>
</Project>

Running gauge tests from jar file

I am new to gauge testing tool .I have a maven project that consists of specs and step implementations. Mvn package phase does generate a jar file with all the required classes. However I cant figure out how i can run the gauge specs using a Main class in java, such that i can just run the jar file to run the tests. Is this possible?
Unfortunately no, Gauge binary must be installed and available to execute the specs.
As the Gauge binary is not written in java it cannot be bundled in a jar file and invoked from a Main class.
If you'd like to automatically download and use Gauge in a CI/CD environment, try something like https://github.com/maven-download-plugin/maven-download-plugin to download gauge into a convenient location as part of your mvn build itself.
More info about this here
There is a way to do this. You have to package maven and gauge inside the project directory and include them in the jar. In the main method, unzip all files, then run a shell script to export maven and gauge in the project directory to $PATH, then execute mvn gauge:execute as usual. It's a bit of a hack as it extracts everything to the directory in which the jar is located, but it works on RHEL 7 and I haven't managed to find a cleaner method.

Add groovy extention module in runtime

I writing gradle plugin for code generation, and it's use groovy org.codehaus.groovy.runtime.ExtensionModule.
But extensions resolve on gradle (daemon) start stage, and add jar with META-INF/services/org.codehaus.groovy.runtime.ExtensionModule into build script classpath has no effect.
How to register ExtentionModule manually?
I don't believe you can, as it says in the documentation:
to use an extension, it has to be available on classpath, as compiled classes, before the code using it gets compiled

Jboss Fuse and Cobertura

I have my application which runs in Jboss Fuse on Linux. I deploy my artifacts as jar files under the /deploy directory. I was planning to make use of Cobertura to get code coverage report after executing my jmeter tests. I instrumented my jars and placed under /deploy. I ran my jmeter tests.
Now I am unable to find the location where .ser file will be present.
I tried searching inside fuse directory.
Can anyone help me in getting Cobertura working with Jboss Fuse?
For most versions of Cobertura, you can add:
-Dnet.sourceforge.cobertura.datafile=<filename>.ser
to the JBoss/JVM startup parameters (e.g. run.conf) to specify explicitly the file where you want the report to be created.
Also, you need to make sure the cobertura.jar itself is present in the classpath if you haven't done so yet.

Visual Studio Code Coverage Not Showing All Assemblies

I have 20 projects in my .SLN file. I am running my unit tests through the Test Explorer and generating the code coverage. Only eight of the projects show up in the coverage (see screenshots). I am using a runsettings file in which I have commented out the contents of all of the <exclude> tags, like so:
<PublicKeyTokens>
<!-- Exclude Visual Studio extensions: -->
<Exclude>
<!--
<PublicKeyToken>^B77A5C561934E089$</PublicKeyToken>
<PublicKeyToken>^B03F5F7F11D50A3A$</PublicKeyToken>
<PublicKeyToken>^31BF3856AD364E35$</PublicKeyToken>
<PublicKeyToken>^89845DCD8080CC91$</PublicKeyToken>
<PublicKeyToken>^71E9BCE111E9429C$</PublicKeyToken>
<PublicKeyToken>^8F50407C4E9E73B6$</PublicKeyToken>
<PublicKeyToken>^E361AF139669C375$</PublicKeyToken>
-->
</Exclude>
</PublicKeyTokens>
I cannot figure out why the other 12 projects are not shown in the coverage results. Any ideas?
Solution Projects:
Code Coverage Results:
Adding <DebugType>Full</DebugType> to target .csproj file, worked for me
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>Full</DebugType>
</PropertyGroup>
The assemblies are not showing up as they are not loaded during the current test run.
Add some simple tests that use a type in each of the other assemblies.
Could you not also add:
<CodeCoverage>
<ModulePaths>
<Include>
<!--Include all loaded .dll assemblies and .exe executables-->
<ModulePath>.*\.dll$</ModulePath>
<ModulePath>.*\.exe$</ModulePath>
</Include>
</ModulePaths>
</CodeCoverage>

Resources