This is a sample repo for setting up API testing in .NET.
It includes:
- Demonstrating mocking services
- Getting application logs into test output by using xUnit's
ITestOutputHelper
- Using Testcontainers to run tests against a real SQL Server
- Run the SQL Server compose file:
docker-compose -f docker-compose.sqlserver.yaml up
- Build and run API through Visual Studio, Rider or command line.
-
Make sure you have Docker running.
-
Run the tests
- Docs: Integration tests in ASP.NET Core
- David Fowler's gist
- What is Testcontainers, and why should you use it?
The EF Core in-memory provider is NOT recommended for use in integration testing:
EF Core also comes with an in-memory provider. Although this provider was originally designed to support internal testing of EF Core itself, some developers use it as a database fake when testing EF Core applications. Doing so is highly discouraged.