Specifying how much testing

Is there a way to pass a number when running cargo test to specify "how much" testing to do?

[ I mean tests can access this number somehow and run for longer depending on the value ]

You probably want an environment variable.

If the choice is binary, you could also consider using a cargo feature and select the amount of testing with #[cfg(feature = "more_testing")] or cfg!(feature = "more_testing"). This gets awkward if you want a more granular scale of testing amount.

Thanks, I used this

let ta : usize = str::parse( &std::env::var("TA").unwrap_or("1".to_string()) ).unwrap();

and then on the command line

cargo test

Why parse the literal, though (especially along with allocating an unnecessary temporary string unconditionally)? You probably meant:

env::var("TA").map_or(1_usize, |s| s.parse().unwrap())
1 Like

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.