Cargo test not running tests

Hi,

For some reason when I run cargo test, 0 tests are ran. Even when I click on Run Test in VS Code, nothing runs. I get the following output:

Executing task: cargo test --package defmt-decoder --lib -- log::format::tests::test_parse_log_template --exact --nocapture 

    Finished test [unoptimized + debuginfo] target(s) in 0.12s
     Running unittests src/lib.rs (target/debug/deps/defmt_decoder-087204f1eb9b6806)

running 0 tests

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

This was working normally a few days ago, not sure why it stopped working. Any ideas?

since you are selectively running specific test and you passed --exact option, I'd suspect maybe you renamed some of your mod or test functions so the test name no longer match. double check your test name. e.g. you can list all tests found by the default libtest test harness by running:

cargo test --lib -- --list
1 Like

Shouldn't VS Code figure out the name of the test? I didn't write that command out. That's the command that gets executed when I click on Run Test (I assume this comes from the Rust Analyzer VS Code plugin).

in that case, it is odd. what's the output if you run the unittest executable directly? e.g. for the example above, try run:

$ target/debug/deps/defmt_decoder-087204f1eb9b6806 --list

it should give a list of tests and benches discovered by libtest.

1 Like

Running this I get 0 tests too:

    Finished test [unoptimized + debuginfo] target(s) in 0.06s
     Running unittests src/lib.rs (/Users/andresovela/dev/defmt/target/debug/deps/defmt_decoder-087204f1eb9b6806)
0 tests, 0 benchmarks

You can find the project here, maybe there's something wrong with the project's structure? https://github.com/andresovela/defmt/tree/customizable-logger

The defmt-decoder crate has a #![cfg(feature = "unstable")] attribute at the top level of the lib.rs, so the whole crate has no source files unless the feature is enabled.

If you run with

cargo test --features unstable --package defmt-decoder -- --list

you should see the tests listed out.

2 Likes

Thank you! Now I see the tests :slight_smile:

The question now would be how do I make VS Code work with --features unstable?

for vscode, these configuration for rust-analyzer might be interesting:

{
    //...
    "rust-analyzer.cargo.features": [],
    "rust-analyzer.runnables.extraArgs": [],
    //...
}

rust-analyzer.cargo.features is used for everything that rust-analyzer need to call cargo to get metadata, while rust-analyzer.runnables.extraArgs is used only when you run tests, benches, examples, etc. (there's also rust-analyzer.cargo.extraArgs but it's over kill if you just need to activate features)

see documents:

Thank you! Now it works :slight_smile: I have no idea why it used to work before without that special config, and why it does not work now :man_shrugging:

did you change your development environment? if so, maybe you have the settings on the old machine, but it's in the user settings instead of workspace settings? just a guess.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.