The Mock function takes the name of a METHOD, FUNCTION or FUNCTION_BLOCK and exchanges the implementation during runtime with the functionality provided by the user.
This is particularly helpful to isolate and control dependencies during unit testing.
Note
The mocking functionality only works while executing tests.
Parameters:
| Name | Type | Section | Description |
|---|---|---|---|
| mockeeFn | STRING |
Input | The fully qualified name, including namespace, of the METHOD, FUNCTION or FUNCTION_BLOCK which is to be mocked. |
| mockFn | STRING |
Input | The fully qualified name, including namespace, of the METHOD, FUNCTION or FUNCTION_BLOCK which is to be used as a mock implementation. |
| payload | IPayload |
Input | Additional payload to store states during tests. |
Note
We do suggest to make use of the NAME_OF functionality, e.g. NAME_OF(SomeFunction). This makes it easier to adapt the test code in case the name of a dependency changes.
You can use multiple mocks inside a single test. This includes multiple different mocks and changing mockFn of an already existing mock.