This chapter covers
- Assessing the testing needs for our web service
- Using Rust’s built-in testing capabilities to create unit tests
- Setting up a conditional testing environment
- Creating a mock server that we can remotely shut down
- Using Warp’s built-in testing framework to test our filters
- Writing integration tests against our running web service
This topic of this last chapter of the book is, for some developers, the most important aspect of writing applications: testing. You can practice test-driven development, where you write tests first. You can choose to write tests directly after having implemented the business logic, or can wait until a large part of the application logic is written before testing it. No one-size-fits-all process exists, and your choice depends on the size of the application and the circumstances you are writing it in.
The same goes for the types of tests you are writing and whether you want to cover 100% of your codebase. The most important point is that you have tests, and that they cover the most critical workflow of your application. Another aspect you should have in mind is to thoroughly test the most complex code. If you change a piece of code you barely understand or that has many side effects throughout your application, that’s the area where you want to have many tests, to ideally cover all possible outcomes.