The replacing procedure is called mock setup and occurs at runtime in the arrange phase of the test code.
AxUnit.Mocking.Mock(in mockeeFn: STRING , in mockFn: STRING) is the mock setup function. The first mockeeFn parameter is the fully qualified name of the function to be mocked. The second mockFn parameter is the fully qualified name of the function to be used in place of the mockeeFn function.
Let us consider following test and mock declaration example which allows to cover the execution path of rect_sig returning 0 when it is called. In the arrange phase the mock setup replaces Siemens.Simatic.S71500.Clocks.GetOperatingTime by GetOperatingTime_returns_1 which returns all the time 1.
{Test}
FUNCTION rect_sig_returns_0_in_first_half_of_period
VAR_TEMP
sig: int;
END_VAR
// arrange
AxUnit.Mocking.Mock('Siemens.Simatic.S71500.Clocks.GetOperatingTime', 'GetOperatingTime_returns_1');
// act
sig := rect_sig(TIME#10ms);
// assert
AxUnit.Assert.Equal(TRUE, 0 = sig);
END_FUNCTION
FUNCTION GetOperatingTime_returns_1 : LTIME
GetOperatingTime_returns_1:=LTIME#1ms;
END_FUNCTION
The next example shows the mock setup replacing Siemens.Simatic.S71500.Clocks.GetOperatingTime by GetOperatingTime_returns_6 which returns all the time 6. This leads to the execution of the path in rect_sig, setting the return value to 1.
{Test}
FUNCTION rect_sig_returns_1_in_second_half_of_period
VAR_TEMP
sig: int;
END_VAR
// arrange
AxUnit.Mocking.Mock('Siemens.Simatic.S71500.Clocks.GetOperatingTime', 'GetOperatingTime_returns_6');
// act
sig := rect_sig(TIME#10ms);
// assert
AxUnit.Assert.Equal(TRUE, 1 = sig);
END_FUNCTION
FUNCTION GetOperatingTime_returns_6 : LTIME
GetOperatingTime_returns_6:=LTIME#6ms;
END_FUNCTION
Note
Use NAME_OF(<function name>) operator instead of fully qualified name of mockeeFn and mockFn. The NAME_OF operator lets you profit from intellisense and refactoring support.
AxUnit.Mocking.Mock(NAME_OF(Siemens.Simatic.S71500.Clocks.GetOperatingTime), NAME_OF(GetOperatingTime_returns_6));