Slightly scary line about testing binary crate?

โš“ Rust    ๐Ÿ“… 2025-06-12    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 5      

surdeus

Warning

This post was published 65 days ago. The information described in this article may have changed.

If our project is a binary crate that only contains a src/main.rs file and doesnโ€™t have a src/lib.rs file, we canโ€™t create integration tests in the tests directory and bring functions defined in the src/main.rs file into scope with a use statement. Only library crates expose functions that other crates can use; binary crates are meant to be run on their own.

That's fine. But then,

If the important functionality works, the small amount of code in the src/main.rs file will work as well, and that small amount of code doesnโ€™t need to be tested.

I'm unsure why wouldn't one test the complete thing? Just the last line sounds scary, but I'm unsure I understand it. I'd still test some one or two lines left.

3 posts - 3 participants

Read full topic

๐Ÿท๏ธ rust_feed