parameterized
Procedural macro based parameterized testing library. Useful, when you want to run a test case with many different input sets.
When defining a parameterized test case, the #[parameterized(...)]
attribute should be used instead of #[test]
.
This crate was inspired by JUnit @ParameterizedTest
.
Examples:
Additional examples can be found at the parameterized-examples repository, and in the tests folder.
Example: Fruits
Example: Add5
Imports
If you prefer not to import this library (with use parameterized::parameterized;
) in every test module, you can put
the following snippet at the top of your crate root:
extern crate parameterized;
IDE 'run test' intent
IntelliJ IDEA recognizes test cases and provides context menus which allow you to run tests within a certain scope
(such as a module or a single test case). For example, in IntelliJ you can usually run individual test cases by clicking
the ▶ icon in the gutter. Unfortunately, attribute macros are currently not expanded by intellij-rust
.
This means that the IDE will not recognize test cases generated as a result of attribute macros (such as the
parameterized
macro published by this crate).
A workaround can be found below (if you have a better solution, please feel free to open an issue; thank you in advance!)
Here we created an empty test case (using the ide!()
macro) which will mark the surrounding module as 'containing test cases'. In
the gutter you will find the ▶ icon next to the module. This allows you to run test cases per module.
Note: intellij-rust
does expand declarative macro's (with the new macro engine which can be
selected in the 'settings' menu), such as this ide!
macro.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.