#assertions #unit-testing #assert #unit

assertor

Fluent assertion library with readable failure messages

2 releases

0.0.2 Apr 30, 2023
0.0.1 Sep 18, 2021

#258 in Testing

Download history 491/week @ 2024-01-11 351/week @ 2024-01-18 974/week @ 2024-01-25 1073/week @ 2024-02-01 1018/week @ 2024-02-08 1316/week @ 2024-02-15 1302/week @ 2024-02-22 1203/week @ 2024-02-29 1345/week @ 2024-03-07 1312/week @ 2024-03-14 1426/week @ 2024-03-21 1008/week @ 2024-03-28 1281/week @ 2024-04-04 1248/week @ 2024-04-11 1445/week @ 2024-04-18 1310/week @ 2024-04-25

5,496 downloads per month
Used in 3 crates

Apache-2.0

115KB
2.5K SLoC

Assertor

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

crates.io license docs.rs

Assertor is heavily affected by Java Truth in terms of API design and error messages, but this 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.

⚠ The API is not fully stable and may be changed until version 1.0.

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