Can I get code coverage analysis on an Interop assembly?

I also asked this question on the MSDN forums and did not find permission:

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3686852&SiteID=1

The main problem here, as I see it, is that the interop compilation does not actually contain IL, which can be instrumental (with the possible exception of a few delegates). So, although I can put together a test project that uses an interaction layer, I cannot figure out how many of the methods and properties that I actually call.

Plan B is to go and write a code generator that creates an RCWW library (wrapping fairings at runtime) and a tool designed to cover the code.

Edit: @Franci Penov,

Yes, exactly what I want to do. The COM components supplied to us are a library of several dozen DLLs containing approx. 3000. We use this library in our application and accuse us of testing this Interop layer, since the group delivering the libraries for us conducts minimal testing. Coverage of the code will allow us to ensure that all interfaces and co-classes are executed. That is all I am trying to do. We have separate test projects that use our own managed code.

Yes, ideally, the COM server team should test and analyze their own code, but we do not live in an ideal world, and I must provide a quality product based on their work. If you can prepare a test report that states that I tested 80% of my code interfaces, and 50% of them do not work in accordance with advertising, I can fix errors when it is necessary to perform corrections, and not workarounds.

The layout you mentioned will be useful, but ultimately will not achieve the goal of testing the Interop layer itself, and of course I would not want to support it manually - we are at the mercy of the COM guys in terms of interface changes.

As I mentioned above, the next step is to create wrappers for wrappers and a testing tool.

+4
source share
2 answers

To answer your question - it is not possible to combine assemblies to cover code. They contain only metadata and do not have executable code, as you yourself specify.

Also, I don't see much point in trying the code to span the interop assembly. You must measure the coverage of the code of the code you write.

From the MDN forum thread you mentioned, it seems to me that you really want to measure how your code uses the COM component. If the goal of your code is to list and explicitly call all the methods and properties of a COM object, you do not need to measure the scope of the code. Testing a module / script requires that your code invoke the correct methods / properties at the right time.

Imho, the right way to do this is to write a layer layout for the COM object and verify that you are calling all methods / properties as expected.

+1
source

Plan C:

use something like Mono.Cecil to weave simple run counts into an interop assembly. For example, check out this section in Faq : “I would like to add some trace functions for the assembly that I cannot debug, can Cecil be used?”

0
source

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


All Articles