I am writing Integration Test for an ASPNetCore web API project. While reading about it I came across two terminologies, first is
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory
and second is
Microsoft.AspNetCore.TestHost
References:
https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.1
https://koukia.ca/integration-testing-in-asp-net-core-2-0-51d14ede3968
I am a little confused, why and which kind of setup I should use to test Web API controllers?
I am following an older approach (TestHost)
because I had my startup class in another assembly (internal) and I had been exposing IWebHostBuilder
to my API project. So, in that case, I could not able to use WebApplicationFactory
which takes Startup.cs
class. And as I have an IWebHostBuilder
reference I could directly use TestServer(IWebHostBuilder)
to create the test client.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.