rust_test_framework
A data-driven testing framework for Rust.
Table of Contents
Features
- Data-Driven Testing (DDT): Run the same test logic with multiple inputs.
- Test Fixtures: Support for
setupandteardownfunctions within a test module. - Procedural Macros: Easy-to-use attributes for defining test cases and fixtures.
- Clean Output: Clear results for individual test cases.
Usage
This project is currently in alpha.
Requirements
- Rust Version: 1.80.0 or higher
- Edition: 2021
Add this to your Cargo.toml:
[]
= "0.1.3-alpha.1"
Example usage:
Inlined Parameters
Use #[test_params] to provide test cases directly in your code. You can stack multiple attributes for multiple test
cases.
use test_params;
Advanced Types and Rust-style Initialization
test_params supports idiomatic Rust syntax for structs, enums, Option, and Result.
use test_params;
use Deserialize;
External Data Sources
Use #[test_params_source] to load test cases from external files. It supports different source types via SourceType.
SourceType::JsonFile
use ;
use Deserialize;
// This will generate a test case for each entry in `tests/data.json`
// if it's a list or inject it as a single entry if it's an object.
// You can also use multiple parameters with external sources.
// Each entry in the JSON array should then be an array of values.
SourceType::JsonString
use ;
use Deserialize;
SourceType::PathMask
PathMask generates a test case for each file matching a glob pattern. The test function must accept exactly one parameter of type &Path or PathBuf.
use ;
use Path;
Mixing Inline Parameters and External Sources
You can combine #[test_params] and #[test_params_source] to run a test with data from multiple sources.
use ;
use Deserialize;
Test Fixtures
Use #[test_fixture] on a module to enable #[setup] and #[teardown] functions.
use ;
License
Licensed under the Apache License, Version 2.0.