November 2017
Intermediate to advanced
264 pages
5h 45m
English
In a more realistic, larger project, tests are separated from the application code:
The code generated by Cargo for a library groups the tests inside a mod tests, a so-called module (see Chapter 8, Organizing Code and Macros; if you prefer, you can come back to this section after having read Chapter 8, Organizing Code and Macros and have a better understanding of modules).
In order to work with functions defined in the main code, we have to add the command use super::*;, which brings all these functions into the scope of the tests module:
pub fn double(n: i32) -> i32 { n * 2 } #[cfg(test)] mod tests { use super::*; ...Read now
Unlock full access