speculate.rs
An RSpec inspired minimal testing framework for Rust.
Speculate uses a syntax extension to generate test functions from the DSL at compile time, which unfortunately requires a nightly version of Rust. I recommend using multirust to easily install and switch between stable and nightly versions of Rust.
Installation
Add speculate to the dev-dependencies section of your Cargo.toml:
[]
= "0.0.17"
And add the following to the top of the Rust file you want to add tests for:
Usage
Speculate provides the speculate! syntax extension.
Inside speculate! { ... }, you can use 5 different types of blocks:
-
describe(or its aliascontext) - to group tests in a hierarchy, for readability. Can be arbitrarily nested. -
before- contains setup code that's inserted before every sibling and nesteditandbenchblocks. -
after- contains teardown code that's inserted after every sibling and nesteditandbenchblocks. -
it(or its aliastest) - contains tests.For example:
it "can add 1 and 2" -
bench- contains benchmarks.For example:
bench "xor 1 to 1000" |b|
Complete Example (from examples/basic.rs)
speculate!
License
MIT