expectest
[] (https://travis-ci.org/zummenix/expectest)
Crate provides matchers and matcher functions for unit testing. Inspired by Nimble for Swift.
Using this library you will receive helpful messages with data that is 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]>
Usage
In your Cargo.toml:
[]
= "0.6.0"
Note: If you're using nightly rust you can use
nightly
feature:[] = { = "0.6.0", = ["nightly"] }
In this case failure messages will be integrated in rust's standard panic message.
In your crate:
extern crate expectest;
You can export all needed functions and types from prelude
module:
use *;
Examples
Check out the tests directory!
Changes
Take a look at change log.
Expectations
Use basic syntax to express expectations:
expect!.to;
expect!.to_not;
expect!.not_to;
Note:
expect!
macro provides a file name and a line number for a failed test case.
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 to 0.001
:
expect!.to;
Order
For types that implement the PartialOrd
trait:
expect!.to;
Use any of the 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 any of the following matchers: be_some
, be_none
Result
There are matchers for the Result<T, E>
type:
expect!.to;
Use any of the following matchers: be_ok
, be_err
Emptyness
There is be_empty
matcher for types that implement Iterator + Clone
trait:
expect!.to;
Count of elements in a collection
There is have_count
matcher for types that implement Iterator + Clone
trait:
expect!.to;
Boolean
expect!.to;
Use any of the following matchers: be_true
, be_false
Alternative crates
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Skeptic Template
Examples in this document were tested using skeptic with the following template:
extern crate expectest;
use *;