January 2019
Intermediate to advanced
520 pages
14h 32m
English
With the utilities we've created so far in this chapter, the unit tests look pretty compact. To test the handler of the /signup path that expects UserForm, we will add a test_signup_with_client function with the #[test] attribute:
#[test]fn test_signup_with_client() { let user = UserForm { email: "abc@example.com".into(), password: "abc".into(), }; test_post("/signup", &user);}
When we run the cargo test command, this function will be called and the test_post call, in turn, will bootstrap a server with a mock server as well.
To test a handler of the /signin path, we will use the following function:
#[test]fn test_signin_with_client() { let user = UserForm { email: "abc@example.com".into(), password: "abc".into(), }; test_post("/signin", ...Read now
Unlock full access