我是Web API的新手。我用C#编写的单元测试继承了代码。但是,当我运行单元测试时,无论控制器名称如何,测试都会通过。例如:http://localhost/api/users - >即使用户拼写错误,单元测试也会通过。Web API单元测试未按预期工作
我在控制器下面的代码:
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);
}
不知道这信息足以告诉我问题出在哪里,但请让我知道如果有更多的信息需要发布。
你使用什么单元测试框架? – jklemmack