且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何测试在C#中的COM依赖对象

更新时间:2023-02-09 14:45:28

我建议您采取COM对象的接口的所有权,这是哪里的依赖倒置原则将开始发挥作用。

I would suggest that you take ownership of the interface of the COM object, this is where Dependency Inversion Principle would come into play.

如果你没有访问源,你必须创建自己的抽象,封装了COM对象,否则就会在你的代码的第三方电话。

If you don't have access to the source, you will have to create your own abstraction that wraps the COM Object, otherwise you will have third-party calls throughout your code.

现在的抽象应该可以被嘲笑。包装的实际执行情况将有COM对象为 HAS-A 关系。

Now the abstraction should be able to be mocked. The actual implementation of the wrapper will have the COM object as a HAS-A relationship.

您会再想有对执行情况的集成测试。

You will then want to have an integration test for the implementation.

您需要把COM对象本身,如果它是类似于数据库或图形渲染引擎或Web服务的东西。

You need to treat the COM object itself as if it was something similar to a database or graphic rendering engine or a web service.