Integrating C++ coverage with sonarqube - c++

I am using Google test framework for C++ unit tests. We are building our projects using MsBuild (runs on teamcity). Now, I want sonarqube to parse the coverage info. We have cfamily plugin in sonarqube. The compatible reports with cfamily plugin are bullseye, vscoverage, gcov, llvm-cov. As per my knowledge, because we can't use gcc for compiling, llvm-cov and gcov are ruled out. Since we are using googletest and also wants to run this on teamcity, vscoverage isn't possible. We aren't using Bullseye. (It is more for functional automation I am told).
So I have decide to use OpenCppCoverage tool. This can generate coverage in cobertura format or generic format specified by sonarqube. I have tried generic format but sonarqube is ignoring the coverage for files but is parsing them successfully.
Exploring more, I tried to use C++ community plugin(cxx). But I wasn't able to disable cfamily plugin so that C++ community can be used.
So I want to know if I can do something else so that coverage of our C++ test projects can be parsed by sonarqube.

Did you try sonar-cxx plug-in from SonarOpenCommunity. This plugin adds C++ support to SonarQube. It's free plug-in and availble with LGPL-3.0 License.

I made the paths in coverage report generated by OpenCppCoverage using OCCSonarQube plugin. Now SonarQube is able to parse the report in generic format.

Related

Xcode and Code Coverage

My application was initially not written for the Mac platform, so it has it's own unit-test system which can be triggered by a command-line. Is it possible to make use of the code coverage support in Xcode by just executing it?
I tried to make it run as a UnitTest which triggers the 'main(...)' function of my application manually (see code block), but since this process is started by the application 'xctest' a lot of things are missing like resources from my application bundle, etc (incorrect or wrong paths, ...).
- (void)testExample {
int main(int argc, char* argv[]);
main(...);
}
Is there any way just to tell Xcode that my application should be started so it can output the code coverage that can be reviewed inside Xcode?
I didn't use XCode coverage tools but I used gcov before. Anyway in this article there is information how to create llvm coverage report. So you can use your unit-test system with llvm's coverage flags and then create .profdata report with llvm-profdata tool.
As I understand Xcode's code coverage tool also creating .profdata report and uses it. I have no straightforward solution but you may find something with this information. If you find a way to make Xcode uses your .profdata it's done :)

JaCoCo test coverage of ant based Netbean Module project

We have inherited a NetBeans Modules project (a.k.a. NetBeans Platform project) which builds using the NetBeans Ant tasks. We want to generate a code coverage report of the project to get an idea of what components are not being unit tested.
Generating a report is not part of the build process, it is simply something we want to do to understand the existing unit test coverage in the project.
We've decided to use JaCoCo to try and generate this. However the native support in NetBeans is for maven based projects. Unfortunately the TikiOne JaCoCoverage plugin currently does not support NetBeans Modules projects.
We are happy to just drive this via CLI to get an initial report. Does anyone have a success means of doing so under the given constraints?
Someone recently posted a related message to one of NetBeans mailing lists - https://netbeans.org/projects/platform/lists/dev/archive/2014-04/message/124
Short version: Cobertura plugin that does what you're looking for is not maintained now but you can build it and run it.
We have been successful in generating the report by doing the following:
Edited the project.properties file to run the JaCoCo agent when unit tests run. This is done by adding the following:
test.run.args=-javaagent:[yourpath/]jacocoagent.jar=destfile=[yourpath/]jacoco.exec
Use Netbeans to run the test task. This produces the jacoco.exec file.
Create a simple ant buildfile to generate reports from an .exec file (see this post)
Run the ant buildfile to generate the report.

Eclipse (CDT) plugin for running tests and browsing report

Google's answers (hear! hear!) and Eclipse Market Place search results on this topic simply drive me crazy! And apparently the proposed SO answers aren't really helpful either.
I'm looking for an Eclipse plugin, that allows me to browse a JUnit report XML compliant unit test report produced from a google test runner.
Nice to have features:
jump to the source from failure reports
run the tests automatically after building.
I'm pretty sure a (free) plugin suitable for Eclipse CDT exists, that realizes these requirements, I'm just too stupid to find it :-). May be any smarter guy/gal here?
Since JUNO there is a C++ Unit testing support package. It is package of the CDT. I only used it with boost test, but AFAIK it also supports googletest.
#mkaes comment pushed me to it!
Install the CDT (Help->Install Software->CDT) optional C/C++ Unit Test support
Create a new Runner using 'Run As -> Run Configurations -> C/C++ Unit Test
Choose 'Google Tests Runner' for 'Tests Runner' in the 'C/C++ Testing' tab
Choose your testing project executable in the 'Main' tab
Run it, and the 'C/C++ Unit' view shows up after (rebuild and) execution
Look here for more illustrated and detailed instructions: Eclipse Juno has landed with unit testing support for C++

Is there an easy way to perform CI with native C++ code (VS2010) and Bamboo?

We're using JIRA with Bamboo as build server for continuous integration.
But I have a native C++ project (using Visual Studio 2010), and apparently Microsoft doesn't support unit tests for native C++ code. There's some tools like WinUnit or cfix that seem to do the job, but neither do I know about their compatibility to Bamboo, nor do I know which tool is the best / easiest to use / has the most features / has best VS compatibility ...
Does someone have experience with that?
Just as a heads up, my current project is using c++ with bamboo for CI. We use googletest for our testing framework. If you have the build run with --gtest_output=xml:{file or Directory} it will produce xml output that can parsed by Bamboo's JUnit Parse task.
I played a bit with CppUnit. The way it works is that you create an executable project which you fill with your test cases. When run, it runs your tests. I think cfix does that but I've never used it for user mode testing. To run the tests as part of your build process, put in a post build step for your test project that runs the test exe. It'll run when you build your Visual Studio solution.

How to enable code coverage without using Visual Studio?

I have 80+ VS2010 solutions, each contains some unit test projects.
All solutions are merged into one big solution before build process.
All tests (or some test subset) are executed after the successful build.
I want to enable test code coverage for all tests to get exact code coverage for all output assemblies.
My question is: how to enable code coverage without using Visual Studio?
Note: I'm using TFS2010 (MSBuild) to build merged solution. VS 2010 Premium is installed on the build server. MSTest is used for test execution.
You can use JetBrain's TeamCity Professional. It is a CI server that supports executing unit tests and calculating code coverage. It is free for small installations.
I think you need to consider deploying a code coverage tool, see here for a comparison (provided you implement .net).We use NCover, which integrated in our TFS-Build in it's console variant and, although it's not trivial to set it up, we 're very satisfied with it.In this post I had briefly described how we inserted NCoverin our build, this might we useful to you even if you go with another tool.
If you create a Vsmdi file in your large solution (ms test will usually do this for you) you can use this to tell the build which assemblies you want to instrument.
This will only provide code coverage for assemblies that have tests run against them. If you're using testrun.config files to decide which tests you want to run, this should be all you need. The code coverage results should then be published to the build drop location
Edit:
This blog post looks like it covers setting up code coverage