Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code coverage tool visual studio 2010 c++

does any know how to do some unit testing in c++ with the code coverage results working in visual studio 2010, I have looked for some answers everywhere. I want to keep the project I am testing and the testing project separate. Using a project the outputs a static lib is not a solution as the code coverage tool in VS 2010 can't put instrumentation code inside of the lib. Ive tried dll as the project to be tested, but then that cant link properly with test created due to the CLR:safe parameter being turned on for tests. Any ideas people? Or are MS just incapable of making a c++ code coverage tool.

like image 761
user531571 Avatar asked Jan 20 '11 05:01

user531571


1 Answers

(Full disclosure: I'm on the team that maintains this feature)

Native C++ code coverage is supported by VS2010, but as you've seen, you can only instrument linked binaries (e.g. .dll or .exe). This means that the code you want to collect coverage for must be linked into a binary image before you instrument it.

What unit test framework are you using? It sounds like your test project is pure managed C++ (/clr:safe). If you build your native C++ project as a DLL, your test project should at least be able to call into the native DLL using P/Invoke calls. By doing this, you don't actually need to link your native .lib into your test project.

like image 112
Chris Schmich Avatar answered Sep 30 '22 09:09

Chris Schmich