How do I set up code coverage in C++ googletest project in Visual Studio 2010 - c++

I have a C++ googletest project building in Visual Studio 2010 professional. This builds a console application which generates XML test result output. How can I set it up to get code coverage information?
I have tried instructions here to instrument the code but viewing the Code Coverage results seems to require Visual Studio Ultimate. Is there any converter for the .coverage files Visual Studio generates?
Bonus points for portable/free/open-source solutions!

You can try OpenCppCoverage: http://opencppcoverage.codeplex.com.
OpenCppCoverage is a code coverage tools for C++ under Windows. It is open-source and works well with google test / Visual Studio C++.
Disclaimer: I am the author of this tool.
Hope that help.
Edit to follow brasofilo advice:
To be more precise about your question, OpenCppCoverage should work with Visual Studio C++ 2010 professional. The only requirement is to support native Pdb files (http://msdn.microsoft.com/en-us/library/yd4f8bd1%28vs.71%29.aspx).
It is open source and free and you can find sources here: https://opencppcoverage.codeplex.com/SourceControl/latest.
What do you mean by portable?
If you mean "Multi platform" -> No, it works only on Windows
If you mean "Portable application" (http://en.wikipedia.org/wiki/Portable_application): OpenCppCoverage required only Redistributable for Visual Studio 2013 to be installed on host (http://www.microsoft.com/en-US/download/details.aspx?id=40784) but it does not write to registry and you can move the binaries where you want (usb key for example).
Hope that help.

I think you can use the VSTEST.Consol.exe for this purpose http://msdn.microsoft.com/en-us/library/vstudio/jj155796.aspx.
According to documentation, it would run tests written against any test framework. You may enable the
/Enablecodecoverage option, which Enables data diagnostic adapter CodeCoverage in the test run.
More information may be found here: http://blogs.msdn.com/b/bhuvaneshwari/archive/2012/06/16/vstest-console-exe-commandline-test-runner.aspx
There is also an open source code coverage tool called ggcov: http://ggcov.sourceforge.net/index.html
Hope that these helps.

Related

Code Coverage for Visual Studio 2017 Community with C++

Are there any plugins for visual studio 2017 which enable to calculate unit test code coverage with C++?
I only found
OpenCppCoverage:
https://marketplace.visualstudio.com/items?itemName=OpenCppCoverage.OpenCppCoveragePlugin
but it seems to be outdated / not working.
Other than that it seems like there are only Code coverage plugins for .Net-Languages but not C++
Are there any other options (besides upgrading to MSVC Enterprise)
I recently tested CPPCoverage, an open source and free extension that works perfectly to perform code coverage of native Visual C++ unit tests.
It is a visual extension (VSIX) and provide details reports. Once installed, Right-click in solution explorer on the test or application project and click "Run code coverage".

Visual Studio 2017 wont show c++ template/extansion

I am trying to use Microsoft visual studio IDE to run my c++ code, however, when I go to create a project, I do not see the option for a c++ project. I tried reinstalling the program to see if I could somehow install the package/extension however it just won't seem to come up.
The only templates that appear are in c# or f#.
If someone could please lead me into the right direction so that I can fix this, it would be great. Thank you.
I don't see any mention of C++ in the release notes.
According to this post on MSDN, there is no C++ support in the Mac version of Visual Studio. It contains links to instructions for using Visual Studio Code, as well as the option to install a VM running Windows.
Apparently Visual Studio Code supports C++ projects, since it can execute external tools. The Microsoft Visual C++ build tools are free for Windows, but I don't think there is a version for the Mac, so some other external compiler is necessary.

Code Coverage Reporting with Visual Studio 2013 Professional for native C++

Using the C++ unit testing framework with Visual Studio 2013 Professional, one can write unit tests and run them from within the IDE, but in order to generate any coverage reports, apparently, one needs to have the Premium or Ultimate edition of Visual Studio.
Is it possible to get code coverage reports with the Professional edition, preferably without installing any third party tools? If not, what alternate options exist for people who are not using the more expensive editions of the IDE?
Please note that it's possible to generate the coverage data by using command line tools, but I am unable to find a way to look at the results. For the sake of reference, here are the steps for command line generation of the coverage statistics:
Build the code to test with with /PROFILE linker switch
Run vsinstr /coverage <binaryName> to instrument the code; make sure that you are inside VS 2013 command prompt
Run start vsperfmon -coverage -output:results to run the profiler
Run your unit tests
Stop the profiler by running vsperfcmd -shutdown
The above will give you a results.coverage file, with no way to view it without the Premium or Ultimate editions as far as I know.
With VS2013 Professional you are out of luck if you want to do it without third party tools Requirements: Visual Studio Ultimate, Visual Studio Premium (http://msdn.microsoft.com/en-us/library/dd537628.aspx). From what I understand you already managed to generate your *.coverage file and you are having problems opening it. Visual Coverage (https://github.com/jsargiot/visual-coverage) tool can help you with that, its very simple to use and it is opensource. If you would like to find more alternatives, see another SO thread: Viewing Code Coverage Results outside of Visual studio. The tools are meant for C# coverage files but from what I understand there should not be any difference.
If you are ready to use third-party libraries, you can use OpenCPPCoverage. It works for me like a command line app. But I couldn't run it like a visual studio plugin at Professional Visual Studio 2013.
One possible way you could get coverage data is by running an instrumentation toolkit on your Unit Test program. The instrumentation tool will tell you how much was covered during execution and you can easily relate this data back to how much coverage your unit tests give you. I did this with an XCode project and OpenPAT but you could do the same with any Visual Studio friendly toolkit.

Visual Studio 2010/2012 Add-in Project Questions

I have already created a simple source code analyses tool for C/C++, but I wanted it to be an extension or tool for Visual Studio 2010 and 2012 editions. It is written completely in C++. For this reason I created it using "Create an Add-in using Visual C++/ATL" option. And then under "Choose Add-in Options", I have some problems. I don't know which one or ones to select. I want it to have a name and icon under Tools section, but on the other hand, my code analyzer can be used from command line too. If someone can advice me which option(s) to select there I would be glad.
My second question is this, when I have opened a source file in Visual Studio, and if I go to Tools -> MyAddin, and press it, I want it to do its job and analyze the code, and show the results in the output section below.
And my last question is that, if I have a C/C++ project with few files let's say, and if I right-click one of the files, I want to see my add-in and be able to execute the add-in from there, not to go always to Tools -> MyAddin. And also the same thing to work if I right-click the project, then it should analyze the all files and show the problems in the output section.
Please note that I have already created the source code analyzer tool in C++, and I have it as a DLL. I can also use it in Linux from terminal, and if I want I can also create a GUI for it, which I plan to do later. But I'm not that much experienced with Visual Studio, especially about add-ins, that's why I need your help. As you can see my first question is a kind of advice, but I think my second and third questions require some source code. I know that it is very hard for you to give me some help without seeing my code, but if you would help me somehow I would be glad.
For Visual Studio 2010 and 2012 you should consider using Extensions, not Add-Ins. It is a new technology introduced in Visual Studio 2010. Extensions come in form of a VSIX packages and are automatically installed in all applicable versions of Visual Studio. If you are not targeting Visual Studio version prior to 2010, I strongly recommend using extensions.
From this point of view, I will not answer any of your technical questions about Add-Ins. Here are a couple of links to start using extensions instead:
Anatomy of a VSIX Package
Building and publishing an extension for Visual Studio 2010
VSX FAQ
Walkthrough: Creating an Options Page
I think you will find valuable information on this topic here: Developing extension packages for Visual Studio 2005/2008/2010/2012 using C# with real-life samples

Static-code analyzer: unmanaged C++ Visual Studio 2008

I develop commercial unmanaged C++ app on Visual Studio 2008, and I want to add a static-code analysis tool.
Any recommendations?
I think it would be real nice if the tool can be integrated into MSVC.
I'm thinking about PC-Lint + Visual Lint
However, I have been taking a hard look at Coverity, Understand, and Klockwork as well.
Price isnt really the issue. I want opinions from people who actually used the tool for unmanaged C++ on MSVC, and they just absolutely loved it.
Lastly, VSTS and Intel Parallel Studio now also offer static code analysis. Nice~
Note: related post suggest Coverity is the best (?) (see last 2 posts)
Beyond all those you mentioned, VS Team Developer edition comes bundled with a nice static analysis tool called prefast. Its (obviously..) well integrated into the IDE, and accessible via the menus.
Its in fact a public release of an MS internal tool - a thin version of a tool called Prefix they run on their builds. Personally, when I faced the same decision, prefast sufficed.
I work for RedLizard building Goanna, a C++ static analysis plugin for Visual Studio. Its focus is on desktop use by a programmer. You can run it on individual files, just as you do the compiler, and it can give you results quickly.
There is a trial available. Right-click a file, select Run Goanna, and the results appear in the Visual Studio warnings list.
You can try CppDepend, a pretty complete c and c++ static analyzer, well integrated with VS 2008, 2010, 2012, 2013 and 2015.
I just started using cppcheck which I like very much due to the low noise.
Although it does not integrate directly with Visual Studio 2008, VS can be customized and you should be able to integrate it directly into the IDE.
I use PVS-Studio static code analyzer.
This static code analyzer good integrated with Visual Studio 2005, 2008, 2010, 2012, 2013.
It has many additional features:
Verification of files which were recently modified several days ago;
Verification of files by their filenames from within the text file
list;
version control systems integration; ability to operate fro m command line
interface;
«False Alarms» marking; saving and loading of analysis
results;
utilizing all available cores and processors;
etc...