3 ms·
Tests are good but moving left by lifting invariants into the type system is better. Compare fn send_email(addr: &str, subject: &str, body: &str) -> Result
by K0nserv 2y ago
Tests are good but moving left by lifting invariants into the type system is better.
Compare
fn send_email(addr: &str, subject: &str, body: &str) -> Result<()>
to
fn send_email(add: &EmailAddr, subject: &str, body: &str) -> Result<()>
In the second case, the edge cases of an empty or invalid email address don't need to be tested, they are statically impossible.
- galangalalgol 2y agoThanks for the small concrete example. I try to explain this a lot. It also makes coverage really easy to get with fewer tests.