How to test Umbraco against a real database
In my last post about Test Driven Development, I briefly touched on testing with a real database and how I used TestContainers to do it. Learning TDD by doing: Umbraco & EF Core Dennis ・ Apr 7 #webdev #tutorial #testing #umbraco In this post I'm going to explain step-by-step how to run some simple tests against an Umbraco project with a real database: Things you need before you get started Setup before writing tests Integration test with EF Core Integration test with an Umbraco site running in-memory Things you need before you get started The first thing you need is docker. If you're using windows like I do, you can install Docker Desktop for windows. We use docker to create new databases on-demand for our tests. You also need: A working Umbraco project A unit test project The code examples in this tutorial are based on xUnit, but the concepts apply to any testing framework that you might use. Setup before writing tests We start by installing the necessary packages into the test project with the following command: dotnet add package Testcontainers.MsSql dotnet add package Testcontainers.Xunit The first thing we need, before we write any tests, is a utility to easily consume test databases. XUnit makes this very easy. We will start with a class that represents our resource: SqlServerDatabase.cs public class SqlServerDatabase : IAsyncLifetime { //

In my last post about Test Driven Development, I briefly touched on testing with a real database and how I used TestContainers to do it.
In this post I'm going to explain step-by-step how to run some simple tests against an Umbraco project with a real database:
- Things you need before you get started
- Setup before writing tests
- Integration test with EF Core
- Integration test with an Umbraco site running in-memory
Things you need before you get started
The first thing you need is docker. If you're using windows like I do, you can install Docker Desktop for windows. We use docker to create new databases on-demand for our tests.
You also need:
- A working Umbraco project
- A unit test project
The code examples in this tutorial are based on xUnit, but the concepts apply to any testing framework that you might use.
Setup before writing tests
We start by installing the necessary packages into the test project with the following command:
dotnet add package Testcontainers.MsSql
dotnet add package Testcontainers.Xunit
The first thing we need, before we write any tests, is a utility to easily consume test databases. XUnit makes this very easy. We will start with a class that represents our resource:
SqlServerDatabase.cs
public class SqlServerDatabase : IAsyncLifetime
{
//