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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With