Natural Mocks™
Typemock Isolator supports the innovative Natural Mocks™ way
of defining expectations by recording them. Natural Mocks are
strongly typed and thus supports Compile Time Checks and Refactoring.
With Natural Mocks™ it is much simpler to define and create
tests that require isolating other parts of the code.
Although Natural Mocks™ is easier, it does not cover all
scenarios and in some cases reflective Typemock is required. The
two are compatible and can be used together.
Using Natural Mocks™
Typemock Isolator has three main entry classes for using Natural Mocks™:
- RecorderManager
This is the entry point to Natural Mocks™ features
- RecordExpectations
This is the control for Natural Mocks™
- MockManager
This is the entry point to the framework - all methods are static,
enabling you to use the framework with customized test classes
RecorderManager Class
The RecorderManager class has two major methods:
- StartRecording()
Initializes the recording session (you can use new RecordExpectations() too)
- GetLastRecordedMock()
Use to bridge between Natural Mocks™ and Reflective Mocks
RecordExpectations Class
The RecordExpectations class has the following major methods:
- Call Expectations
All calls made while the RecordExpectations class is alive will be automatically mocked (see Natural Mocks™ )
- Return Values
Used to intercept the normal flow and to mock a return value
ExpectAndReturn - returns a mock value from a chain of mocked statements (see Returning Values)
- Throwing Exceptions
Used to intercept the normal flow and to mock throwing an exception
ExpectAndThrow - simulates an exception thrown from a chain of mocked statements (see Throwing exceptions)
- Parameter Checking
You can check parameters by calling CheckArguments() (see Checking Arguments)
MockManager Class
The MockManager class is used to verify that all expectations have been satisfied
- Verify()
Completes the tests by verifying all mocked types; must be
called after every test that used Typemock Isolator (see Attributes for a cleaner way to verify the mocks)
Copyright © Typemock Ltd. 2004-2009. All Rights Reserved.