Crates.io | fluent-test |
lib.rs | fluent-test |
version | |
source | src |
created_at | 2025-03-30 12:10:05.400186+00 |
updated_at | 2025-04-19 16:18:26.82693+00 |
description | A fluent, Jest-like testing library for Rust |
homepage | |
repository | https://github.com/mister-good-deal/fluent-test |
max_upload_size | |
id | 1612317 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A fluent, Jest-like testing library for Rust that builds upon the standard testing infrastructure. FluentTest provides expressive assertions with readable error messages while maintaining compatibility with Rust's built-in testing functionality.
.and()
and .or()
operators.Add FluentTest to your project:
cargo add fluent-test --dev
Write your first test:
use fluent_test::prelude::*;
#[test]
fn should_check_values() {
// By default, FluentTest behaves like standard Rust assertions
// To enable enhanced output, configure it:
config().enhanced_output(true).apply();
let my_number = 5;
let my_string = "hello world";
let my_vec = vec![1, 2, 3];
expect!(my_number).to_be_greater_than(3);
expect!(my_string).to_contain("world");
expect!(my_vec).to_have_length(3);
}
You can also enable enhanced output globally by setting the environment variable:
FLUENT_TEST_ENHANCED_OUTPUT=true cargo test
FluentTest provides a comprehensive set of matchers for various types. All matchers support negation through either the
not()
method or the expect_not!
macro.
For complete documentation of all matchers, please see the Wiki documentation.
View Boolean Matchers documentation
View Equality Matchers documentation
View Numeric Matchers documentation
View String Matchers documentation
View Collection Matchers documentation
View HashMap Matchers documentation
View Option Matchers documentation
View Result Matchers documentation
FluentTest provides powerful modifiers to create complex assertions, including:
.not()
method or expect_not!
macro.and()
and .or()
operators// Example of chained assertions
expect!(number).to_be_greater_than(30)
.and().to_be_less_than(50)
.and().to_be_even();
// Example of negation
expect!(value).not().to_equal(100);
View Using Modifiers documentation
FluentTest provides a powerful fixture system for setting up and tearing down test environments:
use fluent_test::prelude::*;
// Define setup function
#[setup]
fn prepare_test_data() {
// Code to run before each test
println!("Setting up test environment");
}
// Define teardown function
#[tear_down]
fn cleanup_resources() {
// Code to run after each test
println!("Cleaning up test environment");
}
// Test with fixtures
#[test]
#[with_fixtures]
fn my_test() {
// This will automatically run setup before and teardown after
expect!(2 + 2).to_equal(4);
}
Key features:
#[before_all]
, #[setup]
, #[tear_down]
, and #[after_all]
#[setup]
, #[tear_down]
, and #[with_fixtures]
#[with_fixtures_module]
to apply fixtures to all tests in a moduleView Test Fixtures documentation
FluentTest is designed to be easily extensible. You can create your own custom matchers to make your tests more expressive and domain-specific.
View Custom Matchers documentation
FluentTest enhances the standard test output with colors, symbols, and improved formatting:
&
) are automatically removed from outputView Output Formatting documentation
FluentTest uses a modular, event-driven architecture:
View Architecture documentation
This project is automatically published to crates.io when:
The publishing workflow will:
This project uses Rust's official LLVM-based code coverage instrumentation to track test coverage. The coverage workflow:
-C instrument-coverage
flagCoverage reports are automatically generated on each push to the master branch and for pull requests.
To generate coverage reports locally:
# Install required components
rustup component add llvm-tools-preview
cargo install grcov
cargo install rustfilt
# Build with coverage instrumentation and run tests
RUSTFLAGS="-C instrument-coverage" cargo test
# Generate HTML report
grcov . --binary-path ./target/debug/ -s . -t html --branch --keep-only "src/**" -o ./coverage
# Generate Markdown report
grcov . --binary-path ./target/debug/ -s . -t markdown --branch --keep-only "src/**" -o ./coverage/coverage.md
Then open ./coverage/index.html
in your browser or view the Markdown report in your favorite editor.
This project is licensed under the MIT License - see the LICENSE file for details.