是否可以模拟 Activator.GetObject()?

发布于 2024-09-16 17:09:26 字数 214 浏览 1 评论 0原文

我正在尝试为使用 .net 远程处理对象的方法编写单元测试。

远程对象是通过使用 Activator.GetObject(typeof(myRemotingObjectType), uri); 创建的

在运行时,uri 是远程对象的服务器 IP 地址。

由于我想编写单元测试,因此我不想初始化任何 .Net 远程处理以减慢测试速度(如果可能)。

谢谢

I am trying to write a unit test for a method that uses a .net remoting object.

The remoting object is created by using Activator.GetObject(typeof(myRemotingObjectType), uri);

During runtime, the uri is server ip address of the remoting object.

Since I want to write a unit test, I don't want to initialize any .Net remoting to slowdown the test if possible.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年已逝 2024-09-23 17:09:26

我建议包装它并让包装器实现一个接口。然后,您可以将包装器替换为模拟等效物以进行测试。

I would suggest wrapping it and have the wrapper implement an interface. You can then swap the wrapper with a mock equivalent for testing purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文