#[cfg(test)] and cargo test, a missing information

I'm currently working on a xmpp-client library and I want it tested as hell. I don't want to reach 100% code coverage but testing is part of the development workflow and moreover Rust natively provides testing and documentation facilities. But, what's the point about #[cfg(test)]? As you may know, in Rust, you can write code in different ways. Either you put everything directly in your src folder within rs files (and where tests are written in the documentation and/or in a test module section) or you can have…

Keep reading

Cargo: How to display print in test command

Sometime you try to understand why an assertion failed. It can be many things and you need some visibility to understand what's wrong with your code. By default cargo test prevent every print. To display it you just need to use this: $ cargo test -- --nocapture Enjoy…

Keep reading