Introducing unit testing
As a TDD practitioner, you will be writing much more unit test code than production code (the regular application code). Unlike other test categories, unit tests will dictate some architectural decisions of your application and enforce DI.
We won’t dwell on long definitions. Instead, we will demonstrate unit testing with a plethora of examples. In this section, we will discuss the xUnit unit testing framework and the unit test structure.
What is unit testing?
Unit testing is testing a behavior while swapping real dependencies with test doubles. Let me back up this definition with an example from WeatherForecastController
in the WFA:
private readonly ILogger<WeatherForecastController> _logger; public double ConvertCToF(double c) { double f = c * (9d / 5d) + 32; _logger.LogInformation("conversion requested"); return f; }
This...