Test Case
Overview
This crate provides #[test_case]
procedural macro attribute that generates multiple parametrized tests using one body with different input parameters.
A test is generated for each data set passed in test_case
attribute.
Under the hood, all test cases that share same body are grouped into mod
, giving clear and readable test results.
Getting Started
First of all you have to add this dependency to your Cargo.toml
:
[]
= "0.3.1"
Additionally you have to import the procedural macro with use
statement:
use test_case;
The crate depends on proc_macro
feature that has been stabilized on rustc 1.29+.
Example usage:
extern crate test_case;
use test_case;
Output from cargo test
for this example:
; ; ; ;
Examples
If your only assertion is just assert_eq!
, you can pass the expectation as macro attribute using =>
syntax:
Which is equivalent to
Attributes and expectation may be any expresion unless they contain =>
, e.g.
Note: in fact, =>
is not prohibited but the parser will always treat last =>
sign as beginning of expectation definition.
Test case names are optional. They are set using ;
followed by string literal at the end of macro attributes.
Example generated code:
Inconclusive (ignored) test cases (since 0.2.0)
If test case name (passed using ;
syntax described above) contains word "inconclusive", generated test will be marked with #[ignore]
.
Generated code:
Note: word inconclusive
is only reserved in test name given after ;
.
License
Licensed under of MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
Contribution
All contributions and comments are more than welcome! Don't be afraid to open an issue or PR whenever you find a bug or have an idea to improve this crate.
Recommended tools:
cargo readme
- to regenerate README.md based on template and lib.rs commentscargo insta
- to review test snapshotscargo edit
- to add/remove dependenciescargo fmt
- to format codecargo clippy
- for all insights and tipscargo fix
- for fixing warnings