parameterized_test::create!()
macro
This small crate provides a parameterized_test::create!()
macro to simplify creating repeated
tests with different arguments.
Inspired by Chris Morgan's StackOverflow post and originally documented in this answer, this macro works by dynamically generating a new macro which, in turn, generates separate tests for each test case passed to the generated macro.
Note: the exact API is still in development and may change in subsequent (pre-1.0) releases.
Syntax
parameterized_test::create()
expects four arguments:
- A name for the test group, which will be used as the submodule name and the name of the generated parameters macro.
- One or more variable names, e.g.
foo
or(bar, baz)
(note multiple variables must be parenthesized). - The test body, multiple statements can be enclosed in
{ ... }
.
Example
This example creates two test cases, tests::even::bad_case
and tests::even::good_case
.
use create;
This example accepts multiple parameters:
use create;