【发布时间】:2015-04-15 18:12:51
【问题描述】:
我是 Web API 的新手。我继承了用 c# 编写的单元测试代码。但是,当我运行单元测试时,无论控制器名称如何,测试都会通过。例如:http://localhost/api/users -> 即使用户拼写错误,单元测试也会通过。
我在控制器中有以下代码:
public async Task TestGetUsers()
{
usersController controller = new usersController(new TestUserRepository());
ApiControllerConfig.SetupControllerForTest(controller, "http://localhost/api/users", HttpMethod.Get);
IHttpActionResult result = controller.Get();
HttpResponseMessage message = await result.ExecuteAsync(CancellationToken.None);
string content = await message.Content.ReadAsStringAsync();
Assert.IsTrue(content.Length > 0);
}
不确定这些信息是否足以告诉我问题出在哪里,但如果需要发布更多信息,请告诉我。
【问题讨论】:
-
你用的是什么单元测试框架?
标签: c# unit-testing asp.net-web-api