speculate.rs
An RSpec inspired minimal testing framework for Rust.
Installation
Add speculate
to the dev-dependencies
section of your Cargo.toml
:
[]
= "0.1"
And add the following to the top of the Rust file you want to add tests for:
extern crate speculate;
use speculate; // Must be imported into the current scope.
Usage
Speculate provides the speculate!
syntax extension.
Inside speculate! { ... }
, you can have any "Item", like static
, const
,
fn
, etc, and 5 special 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 nestedit
andbench
blocks. -
after
- contains teardown code that's inserted after every sibling and nestedit
andbench
blocks. -
it
(or its aliastest
) - contains tests.For example:
it "can add 1 and 2"
You can optionally add attributes to this block:
"ignore" test "should panic" test "should panic with foo" test
-
bench
- contains benchmarks.For example:
bench "xor 1 to 1000" |b|
Complete Example (from tests/example.rs
)
extern crate speculate;
use speculate;
speculate!
License
MIT