test_double Crates.io Rustc Version 1.31+

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:

toml [dependencies] test_double = "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":

```rust

[test_double]

use image::ImageManager;

// Expands to:

[cfg(not(test))]

use image::ImageManager;

[cfg(test)]

use image::ImageManagerMock as ImageManager; ```

If you'd like to provide an alternate subsituted name, you can do so:

```rust

[test_double(IMDummy)]

use image::ImageManager;

// Expands to:

[cfg(not(test))]

use image::ImageManager;

[cfg(test)]

use image::IMDummy as ImageManager; ```

Limitations

#[test_double] can't be used with:

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.

```rust test_doubles! { use image::ImageManager; use texture::TextureManager; }

// Expands to:

[cfg(not(test))]

use image::ImageManager;

[cfg(test)]

use image::ImageManagerMock as ImageManager;

[cfg(not(test))]

use texture::TextureManager;

[cfg(test)]

use texture::TextureManagerMock as TextureManager; ```

Limitations

test_doubles! can't be used with: