Umbraco testing examples now also for Umbraco 17
Source: Dev.to
Tools
| Name | Description |
|---|---|
| xUnit v3 | The testing framework. You can use any testing framework that you like though. |
| NSubstitute | Library for mocking. Any mocking library will work. This project doesn’t do extensive mocking, but for example IPublishedValueFallback is a mandatory parameter for any published content item, even if you don’t actually use it. It’s just convenient to insert a mock. |
| Test Containers | Automatically creates Docker containers while running tests. It is used to create an empty SQL Server database that is automatically cleaned up after testing. |
Notable differences compared to Umbraco 16
Database initialization
The SqlServerDatabase resource no longer creates a second database inside the SQL Server test container. While Umbraco 16 would happily create a new database on boot if it didn’t exist yet, Umbraco 17 does not and will throw connection errors.
For regular use of Umbraco this change makes no significant difference. If you also use EF Core, you may need to pay some extra attention here.
A base URL for integration tests
The WebsiteFixture now sets a fixed base URL when creating a back‑office HttpClient. If you need to use a different domain, this base URL can be adapted, but it must use the https protocol. Compared to Umbraco 16, Umbraco 17 requires HTTPS for back‑office endpoints by default and rejects HTTP requests.
You can see all the changes in this commit:
https://github.com/D-Inventor/automated-testing-in-umbraco/commit/573ef96a155c390ba3d4383bf555f9ff5723b3b4
Additional note
I have given some attention to the example website under test in this repository. The homepage now has a slightly fancier template, but it’s all static content. I haven’t yet tied everything together, as the main focus is demonstrating TDD.
I noticed that the C# version of Playwright doesn’t support screenshot comparison, which prevents snapshot testing for template changes. The JavaScript version does support it, so for more comprehensive end‑to‑end testing you’d need to create an equivalent management API client and scenario builder.
That’s all
That’s everything I wanted to share. Hope you check out the repository, give it a star, and let me know if the testing examples have been helpful. Thank you for reading 😊