3

I'm trying to implement a test environment in C++ and it appears to be much harder than I would expect. Seems like I have 3 options:

1) Injecting dependency through interfaces.

2) Injecting dependency through templates

A good dicussion of these options can be found here: Interfaces vs Templates for dependency injection in C++

3) Making a different executable for each test that requires a mock/stub.

Options 1 and 2 requires a lot of modification of the source code, which I'm not really a fan of. I should not have to sacrifice performance/clarity for the sake of testing. On the other hand, making different projects for each tests also doesn't seem very good.

I would be okay with the overhead that comes with option 3, but I have one big problem that I can't solve: I've not found any tools that allow me to report a valid code coverage from multiple different test executables. Merging test results never consider that the lines tested in one test could be the same line tested in another.

For example, I tried asking for help about the code coverage offered by visual studio but I found no help: Visual studio code coverage from many different unit test projects.

So, are the option 1 and 2 my only valid options to get a valid code coverage report or is there some tools I'm unaware of that would do what I want?

My question is NOT a duplicate of Code Coverage Reporting with Visual Studio 2013 Professional for native C++. I'm perfectly able to generate a code coverage for one test executable. What I'm NOT able to do is generate a cohesive report for multiple tests on multiple different projects.

EX: I have my ProjectA, with 2 different test project (TestProjectA and TestProjectB). If my ProjectA contains 10 block, visual studio code coverage will return something like 7 out of 20 blocks (instead of 10) covered because it doesn't realize TestProjectA and TestProjectB are testing the same code.

Community
  • 1
  • 1
MyUsername112358
  • 1,320
  • 14
  • 39

1 Answers1

0

A tool that can do this is C++ Coverage Validator from Software Verify.

https://www.softwareverify.com/cpp-coverage.php

It can merge runs to a central session as you do each run. Or you can merge runs after the fact into one session. It's designed so that it can handle different test harnesses testing the same core code (in a DLL, library etc) if that's what you're doing.

GUI (for interactive use) or command line support for putting in your test suites. Data is stored in C++ Coverage Validator's format, but you can export to HTML, XML and Cobertura XML.

Disclaimer: I wrote C++ Coverage Validator.

Stephen Kellett
  • 3,078
  • 1
  • 22
  • 25