laboratory
A simple, expressive unit test framework for Rust
Checkout the documentation and the extensive examples over on github.
Laboratory is layer 2 test runner solution that sits on top of the Rust test runner to provide unparalleled features and ease of use.
Features
- before_all, before_each, after_all, after_each hooks
- Different reporter options: spec, minimal, json, json-pretty, rust, dot, tap, list
- Reports test durations in: nanoseconds, microseconds, milliseconds and seconds
- The use of custom assertion libraries
- Exclude tests
- Nested test suites
- Test retry support
- The use of state
- "should panic" testing
- Console highlighting
- Dynamic testing
- Highlights slow tests
- No weird macros to try to figure out or debug!
- Human readable code and test results
Installation
In Cargo.toml:
[]
= "2.0.0"
Then in your test files
Getting Started
Testing a simple function
// from examples/simple.rs
// Here we have one function that does
// one thing: Adds one to whatever number
// we pass to it.
Then run:
$ cargo test -- --nocapture
Result:
running 1 test
### Lab Results Start ###
add_one()
✓ should return 1 when passed 0 (0ms)
✓ should return 2 when passed 1 (0ms)
✓ 2 tests completed (0ms)
### Lab Results End ###
test tests::suite ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s