Unit testing and integration testing for minimal APIs
It’s highly likely that you’ve come across the terms unit testing and integration testing, but by way of a refresher, let’s briefly define them.
Unit testing involves testing individual components of functions of a code base in isolation, whereas integration testing checks how different components of modules of a system interact. In a minimal API, a unit test may simply test that a service does what it should, while an integration test would confirm that an HTTP request to the endpoint uses the services and other components together correctly.
In short, you’re either testing a single unit of code, or you’re testing how different units interact with each other.
Let’s create a unit test for a service that does something very simple: calculate the sum of given numerical values. Here is the service as it looks in Program.cs, where it is registered for dependency injection and used as...