#assert #testing

assertor

Fluent assertion library with readable failure messages

1 unstable release

0.0.1 Sep 18, 2021

#26 in #assertions

Download history 707/week @ 2022-08-07 793/week @ 2022-08-14 776/week @ 2022-08-21 653/week @ 2022-08-28 493/week @ 2022-09-04 429/week @ 2022-09-11 420/week @ 2022-09-18 436/week @ 2022-09-25 428/week @ 2022-10-02 413/week @ 2022-10-09 157/week @ 2022-10-16 50/week @ 2022-10-23 100/week @ 2022-10-30 178/week @ 2022-11-06 75/week @ 2022-11-13 63/week @ 2022-11-20

419 downloads per month
Used in chwp

Apache-2.0

99KB
2K SLoC

Assertor

Assertor makes test assertions and failure messages more human-readable.

Assertor is heavyly affected by Java Truth in terms of API design and error messages. Assertor is a totally different project from Java Truth.

Disclaimer

This is not an official Google product, it is just code that happens to be owned by Google.

Example

use assertor::*;

#[test]
fn test_it() {
    assert_that!("foobarbaz").contains("bar");
    assert_that!("foobarbaz").ends_with("baz");

    assert_that!(0.5).with_abs_tol(0.2).is_approx_equal_to(0.6);

    assert_that!(vec!["a", "b"]).contains("a");
    assert_that!(vec!["a", "b"]).has_length(2);
    assert_that!(vec!["a", "b"]).contains_exactly(vec!["a", "b"]);

    assert_that!(Option::Some("Foo")).has_value("Foo");
}

Failure cases

use assertor::*;

fn test_it() {
    assert_that!(vec!["a", "b", "c"]).contains_exactly(vec!["b", "c", "d"]);
    // missing (1)   : ["d"]
    // unexpected (1): ["a"]
    // ---
    // expected      : ["b", "c", "d"]
    // actual        : ["a", "b", "c"]
}

Feature ideas

  • Color / Bold
  • Better diff: vec
  • Better diff: set
  • Better diff: HashMap

Dependencies