hey all, I have a kind of noob Rust question. Is this correct for me to import my unit tests in main.rs like this?
Is this packaging all the unit tests in with the final build? If I don't add these here none of my tests get run, even I put them in a "tests" folder which is weird because in this "Tests" page of the cargo docs it says that also should do it but it doesn't for me. https://doc.rust-lang.org/cargo/guide/tests.html
However, you may get some unused code warnings, and there is some compilation time spent processing the file unnecessarily. You can and should specify that the module should only be compiled for unit tests:
#[cfg(test)]
mod tennis_scoring_tests;
(If you have just a #[test] function, then there is no need for this. #[test] itself also means #[cfg(test)] for that function.
Perhaps you put them in src/tests/ instead of tests/ (next to the Cargo.toml)? In any case, you don't want that type of tests, because those are "integration tests" â which are not compiled together with the rest of your code. Integration tests can only be used to test libraries (but you are not writing a library), or test binaries by running them, not directly access items from the code like TennisGame.
There are exceptions to this principle but they aren't significant here. âŠī¸