4 releases

0.0.4 Jun 12, 2025
0.0.3 Sep 24, 2024
0.0.2 Apr 30, 2023
0.0.1 Sep 18, 2021

#164 in Debugging

Download history 2367/week @ 2026-01-07 2496/week @ 2026-01-14 3784/week @ 2026-01-21 2303/week @ 2026-01-28 2472/week @ 2026-02-04 3011/week @ 2026-02-11 3685/week @ 2026-02-18 3076/week @ 2026-02-25 3682/week @ 2026-03-04 5968/week @ 2026-03-11 6430/week @ 2026-03-18 4132/week @ 2026-03-25 3389/week @ 2026-04-01 3968/week @ 2026-04-08 3996/week @ 2026-04-15 4291/week @ 2026-04-22

16,365 downloads per month
Used in 7 crates

Apache-2.0

185KB
4K SLoC

Assertor

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

crates.io license docs.rs OpenSSF Scorecard

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"]
}

anyhow

Supports asserting error value of anyhow under anyhow feature flag.

[dependencies]
assertor = { version = "*", features = ["anyhow"] }
use assertor::*;
use anyhow::anyhow;

fn anyhow_func() -> anyhow::Result<()> {
    Err(anyhow!("failed to parse something in foobar"))
}

fn test_it() {
    assert_that!(anyhow_func()).err().has_message("failed to parse something in foobar");
    assert_that!(anyhow_func()).err().as_string().contains("parse something");
    assert_that!(anyhow_func()).err().as_string().starts_with("failed");
    assert_that!(anyhow_func()).err().as_string().ends_with("foobar");
}

Feature ideas

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

Dependencies