Mocking a COM object RRS feed

  • Question

  • I have an application which is using a COM object which is implemented as an exe (actually a full fledged application with GUI, file system persistence and all). Type library is embedded in the exe file.

    I need to unit test my code and to avoid using the real COM object, I would like to use what I believe is a mock object instead.

    Is it possible to create such a mock object (manually, "hand-rolled" or by Visual Studio 2015) directly (which then implements the COM interface) without explicit specifying a "replica" of the COM interface and implement another layer of abstraction using this interface ?

    I guess this sounds quite vague, I am pretty new to unit testing, mocking etc. and I believe this should be a simple thing that I just oversee due to my lack of knowledge (the lack of knowledge is perhaps actually more related to COM interop than mocking)

    Wednesday, February 3, 2016 9:37 AM


All replies

  • Seems like I found out.

    Visual Studio confused me by showing the external COM Object (say its named MyComClassClass in object browser) implementing an interface called MyComClass which showed as empty.

    However, a hidden interface called IMyComClass contains all methods etc. and seems to be useful for mocking.

    The real names obscured for discretion :)

    I have seen this before (that the class exposes members, but the interface which the class is inherited from does not).
    I don't know the reason for this, is this a property of VS or the COM class tlb ?

    Wednesday, February 3, 2016 7:32 PM
  • Thanks for sharing the useful information here, EuroEager!

    >>I don't know the reason for this, is this a property of VS or the COM class tlb ?

    My understanding is that it would be related to the COM class tlb.





    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 4, 2016 9:06 AM