Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between Microsoft.AspNetCore.Mvc.Testing and Microsoft.AspNetCore.TestHost pacakges

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.

like image 642
osotorrio Avatar asked Apr 10 '19 10:04

osotorrio


People also ask

What is Microsoft AspNetCore MVC Analyzers?

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.

Which package component can be added for integration testing of the .NET core API applications?

Sdk package. Entity Framework Core is also used in the tests. The app references: Microsoft.

What is WebApplicationFactory?

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.


1 Answers

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

like image 75
Henk Mollema Avatar answered Oct 22 '22 12:10

Henk Mollema