I have used several times the package Microsoft.AspNetCore.TestHost to host Asp.Net Core Web API applications in my integration test.
With Asp.Net Core 2.1 the package Microsoft.AspNetCore.Mvc.Testing was released. But Mvc.Testing has a dependency to TestHost.
I was wondering which features Mvc.Testing package is offering on top of the TestHost package. Specially when it is used in functional testing to host an API.
Microsoft.AspNetCore.Mvc. ASP.NET Core MVC is a web framework that gives you a powerful, patterns-based way to build dynamic websites and web APIs.
Sdk package. Entity Framework Core is also used in the tests. The app references: Microsoft.
WebApplicationFactory is a class dedicated to creating an in-memory application for use in integration and end-end testing. We can create a class that inherits from WebApplicationFactory and it will handle bootstrapping TestServer and giving us back a HttpClient that can be used for making requests.
The Microsoft.AspNetCore.TestHost
package consists of a set of types (including TestServer
) to enable hosting your application in-memory for testing purposes. The Microsoft.AspNetCore.Mvc.Testing
package provides infrastructure to enable functional testing of applications (including the TestServer
) using the WebApplicationFactory
class.
Check out the docs for more info about integration/functional testing: https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests
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