How to Generate code coverage report using Gtest on Windows by using Gcov and Lcov - c++

I am using gtest for testing my code in C++ with Vs code, I am able to generate test report, but I could not genetare gtest code coverage report, I installed gcov lcov. I would like to know that, is there any way to find out the code coverage gtest or not? as I have googled a lot, but I could not find any possible way to get the code coverage result by using Gcov and Lcov in Windows environment. If there is any possibility, please let me know.
Thank You.
I am expecting Gtest code coverage report by using Gcov and Lcov in HTML format.enter image description here

Related

How to generate complete GCOV report when few testcases gets failed?

I need to generate the test coverage report and I have observed that when all the google testcases gets passed then only GCOV generates the coverage report. But now few of the testcases are getting failed. Is there any way to generate test coverage report with failed testcases?
Platform details :
OS - Ubuntu 18.04
Language - C++17
Test framework - Google test (gtest)
Cmake - v3.21.2
Here is the screenshot of the error.
Kindly suggest.
Thanks.

Integrating C++ coverage with sonarqube

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.

Visual Studio Code Coverage includes unwanted libraries

I have a question about unit testing code coverage when using C++/CLI.
I have managed to get code coverage working in visual studio IDE, and also from the command line using vsinstr and vsperfmon. However the problem I am facing now is that the code coverage includes functions from std library, boost and other libraries that I don't want to get code coverage for.
I have tried the /EXCLUDE option, but it doesn't work at all.
I have the following two .rsp files:
/coverage
/exclude:std::*
/exclude:boost::*
MyExe.exe
/coverage
/exclude:std::*
/exclude:boost::*
UnitTestsDll.dll
I am using the following command to instrument the .exe and unit test dll:
vsinstr #foo.rsp
And then starting the performance monitor:
Start vsperfmon -coverage -output:mytestrun.coverage
After that I run my unit tests from the visual studio IDE, and when they finish I shut down the vsperfcmd.
When I then view mytestrun.coverage in visual studio, it still has all the std and other libraries.
Am I missing something important?
Hope someone can help.
EDIT:
I have tried the following command to exclude the unit tests from the coverage:
vsinstr -coverage "UnitTestsDll.dll" /EXCLUDE:UnitTestsNameSpace.*
Notice that instead of using :: I am using the ., because the unit test namespace is a managed one. After running the code coverage and checking it, it seems to have got rid of the coverage for the unit tests, which is the correct behaviour. So it seems that the /EXCLUDE works on the . separator, and doesn't on the :: separator.

TeamCity reports incorrect code coverage with dotCover for c# unit tests

I am somewhat new to TeamCity. I have set it up for a Visual Studio solution.
I am using NUnit step to run unit tests and dotCover for code coverage. Problem is, there are particular parts of my code that I know are covered by unit tests but in the code coverage report, it shows them with zero coverage.
I know the DLLs are created just fine because I run a dir /s command and can see all the test DLLs.
The NUnit step uses MSIL 4.0 platform and the test path looks like this:
**/bin/Debug/*Tests.dll
There are no filters under code coverage.
Many tests are run. But there are some specific tests that are not present in the search report when I search.
Why is this happening and how do I fix it?
Can you please provide information about your NUnit step, especially about .Net Coverage (Filters).
Can you also confirm that tests are actually run?
Full build log (pasted in pastebin.com or such provider) would be also appreciated.
Stupid me. The DLL that was being ignored was spelled *Test.dll instead of *Tests.dll. I use *Tests.dll in my test path.
The issue got fixed once I changed it to *Test*.dll

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