简体   繁体   中英

Unit test timeout in Rust

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM