Cargo test a binary project?


#1

Is it possible to have test functions (marked with #[test]) that get executed by cargo test inside of a binary project? When I do it the naive way - the same as I would in a library - cargo test reports that there are 0 tests to run.


#2

This is in fact how Cargo works. Are you able to run the binary with cargo run? Perhaps Cargo does not understand that it is a binary?

You can double check by running cargo test --bin my-binary.


#3

Wait now it works… I’m not sure what I did wrong originally, but I guess I just made a dumb mistake before. False alarm!