haleonj
haleonj

Reputation: 1518

Rust tests fail to even run

I'm writing a project to learn how to use Rust and I'm calling my project future-finance-labs. After writing some basic functions and verifying the app can be built I wanted to include some tests, located in aggregates/mod.rs. [The tests are in the same file as the actual code as per the documentation.] I'm unable to get the tests to run despite following the documentation to the best of my ability. I have tried to build the project using PowerShell as well as Bash. [It fails to run on Fedora Linux as well]

Here is my output on Bash:

~/future-finance-labs$ cargo test -- src/formatters/mod.rs
    Finished test [unoptimized + debuginfo] target(s) in 5.98s
     Running target/debug/deps/future_finance_labs-16ed066e1ea3b9a1

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Using PowerShell I get the same output with some errors like the following:

error: failed to remove C:\Users\jhale\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\jhale\future-finance-labs\target\debug\build\mime_guess-890328c8763afc22\build_script_build-890328c8763afc22.build_script_build.c22di3i8-cgu.0.rcgu.o: The system cannot find the path specified. (os error 3)

After my initial excitement at the prospect of writing a few tests that passed on the first attempt, I quickly realized all the green was indicative; rather, of a failure to even run the tests. I just want to run the unit tests. Running cargo test alone without a separate and file fails as well. Why can't I run any test in this project with my current setup?

Upvotes: 4

Views: 2657

Answers (1)

kmdreko
kmdreko

Reputation: 60692

It can't find your test because the rust compiler doesn't know about it. You need to add mod aggregates to main.

mod aggregates;

fn main() {
    println!("Hello, world!");
}

After you do that, you'll see that your aggregates/mod.rs doesn't compile for many reasons.


And as Mihir was trying to say, you need to use the name of the test, not the name of the file to run a specific test:

cargo test min_works
cargo test aggregates

See also:

Upvotes: 4

Related Questions