expectest 0.1.8

Library provides functions for unit testing with human-readable syntax. (WIP)
Documentation

expectest

[Build Status] (https://travis-ci.org/zummenix/expectest)

Work In Progress

Library provides functions for unit testing with human-readable syntax. Inspired by Nimble for Swift.

Using this library you will receive nice messages with data that used in test case, example:

let result = vec![1, 2, 2];
expect!(result).to(be_equal_to([1, 2, 3]));

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:

[dev-dependencies]
expectest = "*"

In your crate:

#[cfg(test)]
#[macro_use(expect)]
extern crate expectest;

You can export all needed functions and types from prelude module:

use expectest::prelude::*;

Expectations

Use basic syntax to express expectations:

expect!(...).to(...);
expect!(...).to_not(...);
expect!(...).not_to(...);

Note: You can use expect function instead of expect! macro in that case you will not see file and line where the test fails.

Equality

For types that implement the PartialEq trait:

expect!("hello".to_string()).to(be_equal_to("hello"));

Closeness of float numbers

There is a way to check if two float numbers are close each other:

expect!(12.1_f64).to(be_close_to(12.0).delta(0.1));

With default delta equal 0.001:

expect!(12.001_f64).to(be_close_to(12.0));

Order

For types that implement the PartialOrd trait:

expect!(1).to(be_greater_than(0));

Use following matchers: be_less_than, be_less_or_equal_to, be_greater_than, be_greater_or_equal_to

Boolean

expect!(9 == 9).to(be_true());

Use following matchers: be_true, be_false

Alternative crates

License

MIT