# fluent-asserter [](https://github.com/mirind4/fluent-asserter) [](https://crates.io/crates/fluent-asserter) [](https://docs.rs/fluent-asserter) [](https://github.com/mirind4/fluent-asserter/actions?query=branch%3Amain)
## Introduction A library to write test assertions with a fluent interface. Writing clean tests is as important as writing clean production code. This library contains test asserters for many kind of Rust types to produce clean assertions in our automated tests. It also helps to enhance the Test-Driven Development (TDD) experience, resulting in clean, ergonomic and maintainable tests. ## Usage Add the dependency to your `Cargo.toml`: ```toml [dependencies] fluent-asserter = "0.1.9" ``` Then import the asserters via the prelude ```rust use fluent_asserter::prelude::*; ``` Now you should be able to write test assertions with a fluent syntax in your tests. In the next sections, I show you how. ## String and string slice assertions You can write string assertions for both String and str slices ```rust #[test] fn string_assertions() { assert_that!("Life tastes great!").is_equal_to("Life tastes great!"); assert_that!("Life tastes great!").contains("great"); assert_that!("Life tastes great!").starts_with("Life"); assert_that!("Life tastes great!").ends_with("!"); assert_that!("Life tastes great!").is_not_empty(); assert_that!("Life tastes great!").has_length(18); assert_that!("Life tastes great!").contains_any(&["Life", "awesome"]); assert_that!("Life tastes great!").contains_all(&["Life", "tastes", "great!"]); } ``` ## Number assertions ```rust #[test] fn number_assertions() { assert_that!(21).is_equal_to(21); assert_that!(21).is_smaller_than(22); assert_that!(21).is_smaller_than_or_equal_to(21); assert_that!(21).is_greater_than(20); assert_that!(21).is_in_range(21,31); assert_that!(21).is_not_in_range(10,20); assert_that!(3.14159).is_approx_equal(3.142, 0.001); } ``` ## Boolean assertions ```rust #[test] fn boolean_assertions() { assert_that!(true).is_true(); assert_that!(false).is_false(); } ``` ## Panic assertions ```rust #[test] fn panic_assertions() { assert_that_code!(|| panic!("An error occurred!")) .panics() .with_message("An error occurred!"); assert_that_code!(|| println!("Life tastes great!")).does_not_panic(); } ``` ## Iterator assertions ```rust #[test] fn iterator_assertions() { assert_that!(vec!["tasty", "delicious", "lovely"]).is_equal_to(vec!["tasty", "delicious", "lovely"]); assert_that!(vec!["tasty", "delicious", "lovely"]).contains("delicious"); assert_that!(vec!["tasty", "delicious", "lovely"]).contains_all(&["tasty", "delicious", "lovely"]); assert_that!(vec!["tasty", "delicious", "lovely"]).has_count(3); assert_that!(vec!["tasty", "delicious", "lovely"]).does_not_contain_any(&["awesome", "amazing"]); assert_that!(vec!["tasty", "delicious", "lovely"]).is_not_empty(); } ``` ## Iterator assertion for structs ```rust #[derive(Clone)] struct Person { name: String, age: i32, } #[test] fn iterator_assertion_for_struct() { let people: Vec