test_double

A procedural macro that can swap in mock objects, dummy objects, or other test doubles only when testing. Requires Nightly Rust.
There are many limitations at present:
- Does not support grouped imports, like
use blah::{foo, bar}; - Does not support nested paths, like
use blah::{*, something::{foo, bar}}; - The substituted type can't be changed when using the function-like macro
To use, add the following to your Cargo.toml:
[]
= "0.1.1"
Note that this crate has not yet reached version 1.0, so the API may change drastically between releases.
Substituting One Type
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 change the subsituted name, you can do so:
use ImageManager;
// Expands to:
use ImageManager;
use IMDummy as ImageManager;
Substituting Multiple Types
If you'd like to substitute multiple types at once, you can use the function-like macro. Note that this does not support changing the substituted name yet.
test_doubles!
// Expands to:
use ImageManager;
use ImageManagerMock as ImageManager;
use TextureManager;
use TextureManagerMock as TextureManager;