Search code examples
c#comcode-coverage

Code coverage for COM API


I am trying to get code coverage in VS 2017 Enterprise for some SpecFlow tests. The purpose of the tests are to connect to a COM service and use all of the exposed APIs.

When I run "Analyze Code Coverage", the results are only showing the lines and blocks covered where the SpecFlow statements correlate to my test code. What I want is at least what percent of the exposed API calls are being executed in the tests.

Is there a way to get this level of detail? The COM service is written in C++ while the tests are written in C#. Not sure if that really makes a difference.


Solution

  • If you are calling COM from the .NET runtime, whether you realize it or not, you are using a Runtime-Callable Wrapper (RCW).

    There are a couple ways to create an RCW. One way is to create it implicitly by adding a reference in visual studio. Another way is to use Tlbimp.exe to create a .NET assembly that contains the wrapper. I suggest you use the latter method, and focus your code coverage statistics on the wrapper code. If you achieve a high code coverage level on the wrapper, it means you are calling a high percentage of the underlying COM object's methods.