Since K1, the Kladde has tested its rules, and since lesson 2.3.2 the API’s handlers too, as ordinary methods without a server. But these tests don’t check a lot: whether a route is right, whether the JSON has the right names, whether a service is registered at all, whether the booking form’s error message sits at the right field, whether the booking gets all the way to the confirmation in the browser. So far you’ve checked that by hand with curl -i and in the browser. In this module, automated tests take that over, and in the end they all run in every pull request.

In this lesson you learn about the four kinds of tests a web application needs and when each is the right one. Then you take a closer look at how dotnet test starts the tests and how it notices that a run checked nothing at all. Finally, you set up the test projects this module needs.

Where the Kladde stands

This module builds on the state after module 2.5. In the solutions, the Kladde looks like this:

Kladde.slnx
global.json             SDK version and Microsoft Testing Platform (lesson 1.8.1)
Directory.Build.props   nullable on, warnings as errors
check.ps1               format and tests before every commit (lesson 1.8.5)
.github/workflows/tests.yml
src/
  Kladde.Core/     model and rules: Contact, EmailAddress, Appointment, TimeRange, Result<T>, Error, ErrorCodes,
                   IKladdeStore, KladdeBook, the free times FreeSlots (lesson 2.5.6)
  Kladde.Data/     KladdeDbContext, the store with EF Core, migrations (module 2.4)
  Kladde.Files/    the JSON store from K1, only for the console now (lesson 2.3.1)
  Kladde.Web/      API (module 2.3), Blazor pages and components (module 2.5), BookingOptions
  Kladde.Console/  the console from K1
tests/
  Kladde.Core.Tests/     the core’s rules (since lesson 1.8.1)
  Kladde.Console.Tests/  the console’s menus (since lesson 1.8.3)
  Kladde.Data.Tests/     mapping, seed and contract of the store (since lesson 2.4.6)
  Kladde.Web.Tests/      the API’s handlers as methods (since lesson 2.3.2)

If your files, classes or folders are named differently, keep your names and carry the steps over. That’s not a mistake. The same goes for this module’s examples: they show the solutions’ Kladde. Where yours is built differently, for instance where your rule for free times has other parameters, the cases and the limits stay the same.