Mock.disableParentMethods

Disable parent methods being called if mock replacements are not implemented. If parent methods have been disabled a helpful assert error will be raised on any attempt to call methods that haven't been replaced. This is helpful if it's necessary to disable all behaviour of the mocked class.

Has no effect on mock objects derived from interfaces, by default all mocked interface methods assert an error until replaced.

class Mock(C)
void
disableParentMethods
(
string file = __FILE__
,
size_t line = __LINE__
)
if (
is(C == class) ||
is(C == interface)
)

Parameters

file
Type: string

The file name where the error occurred. The value is added automatically at the call site.

line
Type: size_t

The line where the error occurred. The value is added automatically at the call site.

Examples

1 import dunit.mockable;
2 
3 class T
4 {
5    mixin Mockable!(T);
6 }
7 
8 unittest
9 {
10    auto mock = T.getMock();
11    mock.disableParentMethods();
12 
13    // All mock object methods that are used in the test
14    // must now be replaced to avoid an error being thrown.
15 }

See Also

Meta