Is there a way to specify a timeout for a specific unit test in Rust?
The only way to do it so add it to the test case as a hardcoded argument: https://docs.rs/ntest/0.7.2/ntest/index.html
But I wanted to ask if there is a way to provide in the command line as an argument to running test. Something like:
cargo test <timeout?>
You can get help on the test runner with cargo test -- --help
. In particular you will find:
--ensure-time Treat excess of the test execution time limit as
error.
Threshold values for this option can be configured via
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION`
and
`RUST_TEST_TIME_DOCTEST` environment variables.
Expected format of environment variable is
`VARIABLE=WARN_TIME,CRITICAL_TIME`.
`CRITICAL_TIME` here means the limit that should not
be exceeded by test.