expectest
[] (https://travis-ci.org/zummenix/expectest)
Work In Progress
Library provides matchers and matcher functions for unit testing. Inspired by Nimble for Swift.
Using this library you will receive nice messages with data that used in test case, example:
let result = vec!;
expect!.to;
Test fails and gives us a message:
expected to be equal to <[1, 2, 3]>, got <[1, 2, 2]>
Note: You need to use
cargo test -- --nocapture
to see output from tests.
Usage
In Cargo.toml:
[]
= "*"
In your crate:
extern crate expectest;
You can export all needed functions and types from prelude
module:
use *;
Expectations
Use basic syntax to express expectations:
expect!.to;
expect!.to_not;
expect!.not_to;
Note: You can use
expect
function instead ofexpect!
macro in that case you will not see file and line where the test fails.
Equality
For types that implement the PartialEq
trait:
expect!.to;
Closeness of float numbers
There is a way to check if two float numbers are close each other:
expect!.to;
With default delta
equal 0.001
:
expect!.to;
Order
For types that implement the PartialOrd
trait:
expect!.to;
Use following matchers: be_less_than
, be_less_or_equal_to
, be_greater_than
, be_greater_or_equal_to
Option
There are matchers for the Option<T>
type:
expect!.to;
Use following matchers: be_some
, be_none
Result
There are matchers for the Result<T, E>
type:
expect!.to;
Use following matchers: be_ok
, be_err
Emptyness
There is be_empty
matcher for types that implement IsEmpty
trait:
expect!.to;
Note:
IsEmpty
trait implemented by library for following types:String
,&str
,Vec<T>
,&[T]
.
Boolean
expect!.to;
Use following matchers: be_true
, be_false
Alternative crates
License
MIT