11 Testing your Rust application
This chapter covers:
- Assessing the testing needs for our web service.
- Using Rusts built-in testing capabilities to create unit tests.
- Setting up a conditional testing environment.
- Creating a mock-server which we can remotely shutdown again.
- Using warps built-in testing framework to test our filters.
- Writing integration tests against our running web service.
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 the tests directly after having implemented the business logic, or you wait until a large part of the application logic is written before testing it. There is no one-size-fits-all, and it depends on the size of the application and the circumstances you are writing it in.
The same goes for what types of tests you are writing and if you want to cover 100% of your codebase or not. 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: Test the most complex code thoroughly. If you make a change on a piece of code you barely understand or that has many side-effects throughout your application, that’s the area you want to have many tests which ideally cover all possible outcomes.