Cargo test doesn't work targeting specific test

Cargo test doesn't work targeting specific test. When you have several test on the same test folder, cargo tries to compile and run all of them.

The solutions I've seen on this don't work either. There is something essentially wrong on cargo, because its options are not picked up.

If not solutions on this, I am going to throw cargo away creating my own Makefile for compiling and testing. This is traditionally well done in C++, where you are in control.

In any case, I would like to filter out, ignore or something to make this exact testing a reality.

How are you trying to do this? Do you use the --test <name> flag, or something else?

1 Like

Cargo definitely does allow targeting specific test, namely:

  • targeting specific compilation unit with tests via -p, —lib, —test options
  • targeting a specific test within compilation unit (last positional argument, —exact flag)

Could you give a minimal reproducible example which doesn’t work for you? Specifically, what is the project layout and the command line you are using?

With the information given so far, it’s sadly impossible to be significantly more helpful than “no, it works” :slight_smile:

4 Likes