Chapter 1: Hello, You!
In the previous chapter we wrote a greet function and then wrote the tests.
#![allow(unused_variables)] fn main() { fn greet() -> String { String::from("Hello, World!") } #[cfg(test)] mod tests { use super::greet; #[test] fn test_greet() { assert_eq!("Hello, World!", greet()); } } }
From this point on we will be writing tests first.
Our next requirement is to let us specify the recipient of the greeting.
Let's start by capturing these requirements in a test. This is basic test driven development and allows us to make sure our test is actually testing what we want. When you retrospectively write tests there is the risk that your test may continue to pass even if the code doesn't work as intended.