Chapter 20. Testing your application
This chapter covers
- Creating unit test projects with xUnit
- Writing unit tests for custom middleware and MVC controllers
- Using the Test Host package to write integration tests
- Testing code dependent on EF Core with the in-memory database provider
When I first started programming, I didn’t understand the benefits of automated testing. It involved writing so much more code—wouldn’t it be more productive to be working on new features instead? It was only when my projects started getting bigger that I appreciated the advantages. Instead of having to manually run my app and test each scenario, I could press Play on a suite of tests and have my code tested for me automatically.
Testing is universally accepted as good practice, but how it fits into your development process can often turn into a religious debate. How many tests do you need? Is anything less than 100% coverage of your code base adequate? Should you write tests before, during, or after the main code?