Visual Studio 2010 C ++ Code Coverage Tool

Does anyone know how to run some unit tests in C ++ with code coverage results working in visual studio 2010, I was looking for answers for all occasions. I want to save the project that I am testing and the testing project separately. Using a project, static lib outputs are not a solution, since the code coverage tool in VS 2010 cannot put toolkit code inside lib. Ive tried the dll as a test project, but then this link did not match the test created due to the inclusion of CLR: a secure parameter for testing. Any ideas from people? Or MS is simply unable to create a tool to cover C ++ code.

+4
source share
2 answers

(Full disclosure: I am in a team that supports this feature)

Native C ++ code is supported by VS2010, but, as you saw, you can only link binaries (e.g. .dll or .exe). This means that the code you want to cover the coverage must be bound to the binary image before you produce it.

What unit test structure are you using? It looks like your test project is managed by pure C ++ ( /clr:safe ). If you create your own C ++ project as a DLL, your test project should at least be able to call your own DLL using P / Invoke calls. By doing this, you actually do not need to associate your native .lib with your test project.

+6
source
 //MyTestfile #include "stdafx.h" #include "MathFuncsDll.h" using namespace System; using namespace System::Text; using namespace System::Collections::Generic; using namespace Microsoft::VisualStudio::TestTools::UnitTesting; namespace anothertest { [TestClass] public ref class cuttwotest { public: [TestMethod] void TestMethod1() { Assert::AreEqual ((MathFuncs::MyMathFuncs::Add(2,3)), 6, 0.05); } }; } 
0
source

Source: https://habr.com/ru/post/1336264/


All Articles