Testing the Rocket application
Besides putting the test in the src
directory, we can create a test in Rust files in the tests
directory inside the root directory of the application. When we run cargo test
, the command line will look into the tests
directory and run any test found there. People usually use tests in the src
directory for unit testing and write functional tests in the tests
directory.
The Rocket framework provides a rocket::local
module, which contains modules, structs, and methods to send requests to the local Rocket application. The main purpose of sending a non-networked request to the local Rocket application is to inspect the response and ensure that the response is what we expected, mainly for testing.
Let's try implementing integration testing for our application by following these steps:
- In the root directory of the application, add a new directory named
tests
. Inside thetests
directory, create a file namedfunctional_tests.rs
. - Inside...