Mockable.getMock

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

mixintemplate Mockable(C)
version(unittest)
static
getMock
(
A...
)
()
if (
is(C == class) ||
is(C == interface)
)

Parameters

args A

The constructor arguments of the host class.

Examples

import dunit.mockable;

class T
{
    mixin Mockable!(T);
}

unittest
{
    import dunit.toolkit;

    auto mock = T.getMock();

    assertTrue(cast(T)mock); // Mock extends T.
}

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