【发布时间】:2020-02-27 20:38:38
【问题描述】:
我将我的测试类定义如下,并创建了一个测试。我对如何调用我的 Controller 感到困惑。我使用同一个客户端进行了两次相同的 GetAsync 调用,但看起来每个调用都会命中控制器的不同实例(基于 GetHashCode() 的值)......所以......每个 client.*Async() 调用就像GetAsync,PutAsync .. 总是点击不同的控制器实例?即使使用相同的客户端?有什么办法可以打到同一个实例吗??
// My test class is defined as:
public class ApiControllerIT : IClassFixture<WebApplicationFactory<Startup>> {
public ApiControllerIT(WebApplicationFactory<Startup> factory)
{
_factory = factory;
}
// test case
[Theory]
[InlineData("/api/values")]
public async Task GET_All_ReturnSuccessAndCorrectContent(string url)
{
try
{
// Arrange
var client = _factory.CreateClient();
// Act
var response = await client.GetAsync(url);
response = await client.GetAsync(url);
}
...
}
【问题讨论】:
标签: asp.net-mvc asp.net-core integration-testing