test_double

A procedural macro that can swap in mock objects, dummy objects, or other test doubles only when testing.
To use, add the following to your Cargo.toml:
[]
= "0.2.0"
Note that this crate has not yet reached version 1.0, so the API may change between releases.
Substituting One Type: #[test_double]
The substituted name defaults to the original name, postfixed with "Mock":
use ImageManager;
// Expands to:
use ImageManager;
use ImageManagerMock as ImageManager;
If you'd like to provide an alternate subsituted name, you can do so:
use ImageManager;
// Expands to:
use ImageManager;
use IMDummy as ImageManager;
Limitations
#[test_double] can't be used with:
- Glob imports, like
use blah::*; - Grouped imports, like
use blah::{foo, bar};, when providing an alternate substituted name
Substituting Multiple Types: test_doubles!
If you'd like to substitute multiple types at once, you can use the function-like macro. Note that this does not support providing an alternate substituted name.
test_doubles!
// Expands to:
use ImageManager;
use ImageManagerMock as ImageManager;
use TextureManager;
use TextureManagerMock as TextureManager;
Limitations
test_doubles! can't be used with:
- Glob imports, like
use blah::*;