我使用WCF REST服务创建了一个新的解决方案。现在我需要对服务进行单元测试。例如,这里有一个REST服务url:
汽车/{id}
GET方法应该返回一个带有querystring中提供的id的car对象。如何通过VS单元测试项目进行配置?
简单,创建一个自托管的单元测试,即
[TestInitialize]
public void Before_Each_Test()
{
var host = new ServiceHost(typeof(CarService));
// Override with local endpoint, i.e. a TCP connection, local IP etc
host.Open();
}
当然,不要忘记在TestCleanup中关闭主机。