How to make cargo test show only the test which ran?

Viewed 192

I run cargo test and I get this junk before and after the actual test file:

root@ub:~/backend/utils# cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.21s
     Running unittests (target/debug/deps/utils-d206bcff05f45684)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/helpers.rs (target/debug/deps/helpers-21ab86543f613060)

running 1 test
test tests::test_add ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests utils

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

So see those two running 0 tests? How can I remove them and just show the actual test that ran?

1 Answers

Here is a way to reduce the amount of extra output: If a particular target (library, binary) does not have any tests, then you can disable running tests in it via your Cargo.toml:

[lib]
test = false
doctest = false

[[bin]]
name = "my-binary"
test = false

That will eliminate the “running 0 tests” sections in the output of cargo test.

Of course, this creates the risk that you will later discover that you wrote a test and it isn't running, but that can be helped by adopting the test-driven-development habit of writing tests you know will fail first.

Related