【发布时间】:2009-10-01 19:59:15
【问题描述】:
假设我有一个类似以下的课程:
public class Test{
private RemoteDoc.Documentation docService = new RemoteDoc.Documentation();
public Test(){}
}
所以这使得单元测试变得困难,因为它依赖于代理类。您可以像这样通过构造函数传入对象:
public class Test{
private RemoteDoc.Documentation docService;
public Test(RemoteDoc.Documentation serv)
{
docService = serv;
}
}
现在在我的单元测试中,我可以实例化 Test 类并将一个模拟对象传递给构造函数。但是,此解决方案并不理想,因为现在其他类必须了解 RemoteDoc.Documentation 代理类并对其进行显式引用。有什么好的办法解决这个问题?
编辑:更清楚地说,RemoteDoc.Documentation 是 Web 参考的代理类。想象一下,如果您使用的是 salesforce.com 的 api,而您真正拥有的只是 wsdl 和 disco 文件。
【问题讨论】:
标签: c# .net asp.net web-services unit-testing