things in Rust test
2022/07/31 COSCUP
Antonio Yang
Rust offers a good tool for testing, we can quickly run tests with test cases, examples, and documents, and also can be selected by features with cargo
cargo test
cargo test add_
cargo test --examples cargo test --example=add-twice
cargo test
cargo test --features=redundant
Integration test is not well considered in Rust
Test
Test
Hard to know the test ignored
Alway pass in the test case when ignoring
Not really know why ignoring
Check envar when test running
Conditions: envar, file, http service, tcp socket, user, cpu, .. etc.
cargo test
Show ignore in the test case when ignoring
Show ignore message
Check condition when test case compiling
Integration test is not well considered in Rust
#[test]
fn test_case () {
ignore!("some message")
}
#[test]
#[ignore]
fn test_case () {
}
Note: ignore! is not really defined in Rust
#[test]
fn test_case () {
ignore!("some message")
}
#[test]
fn test_case () {
panic!("some message")
}
Note: ignore! is not really defined in Rust
Define return code
Test result base on return code
Parse panic message
library/test/src/test_result.rs
cargo test -- --include-ignored
cargo test -- --ignored
Run ignored and not ignored tests
Run only ignored tests
These two options are designed for ignoring in build time, and not suitable for ignoring in runtime
fn test::mark_ignored
— mark the current test as ignored; continue.fn test::mark_failed
— mark the current test as failed; continue.fn test::ignore
— mark the current test as ignored; continue if --include-ignored
, otherwise abort (unwind).fn test::skip
— mark the current test as ignored; if --include-ignored
, fail; abort (unwind).
{test::ignore(); test::fail()}
.fn test::fail
— mark the current test as failed; abort (unwind).If conditional statements
in side a String
A lot of documents for a small test because there is no standard way to do this
Djaesuhn.tjl @ flicr CC BY-SA 2.0
yanganto
yanganto