Mockable.getMock

Injected by the Mockable mixin template this method allows creation of mock object instances of the mockable class.

mixin template Mockable(C)
version(unittest)
getMock
(
A...
)
()
if (
is(C == class) ||
is(C == interface)
)

Parameters

args
Type: A

The constructor arguments of the host class.

Examples

1 import dunit.mockable;
2 
3 class T
4 {
5    mixin Mockable!(T);
6 }
7 
8 unittest
9 {
10    import dunit.toolkit;
11 
12    auto mock = T.getMock();
13 
14    assertTrue(cast(T)mock); // Mock extends T.
15 }

Templates:

Templated classes are supported when creating mocks. Simply include the template parameters for the class when calling the 'getMock' method.

auto mock = T!(int).getMock(); // Get a mock of T!(int).

Meta