Specific macros are available in the methods of ETEST objects. You can use these macros to control the test execution and determine the result of a test case.
Macros are called in the same way as methods. In contrast to a function call, a macro call can write variables of the calling method and can trigger a return of the calling method.
Macros are allowed in the following methods of test cases and resources:
Prepare
Execute
CleanUp
You can also use macros in methods that are called with ASSERT_SUBMETHOD
.
Finalize
.
Macros in other objects do not have any effect. This is indicated by a message that is displayed in the view.
In the methods of test cases and resources, the following macros are possible:
Macro call-up |
Description |
---|---|
|
FALSE: Execution is not completed successfully. TRUE: Execution is completed successfully. |
|
FALSE: Execution is not completed successfully. TRUE: Execution is completed successfully.
|
|
FALSE: Test result is inconclusive. The test result is inconclusive to indicate that a test could not be carried out. The cause may be, for example, that a hardware device required for the test is not available on the test system. TRUE: Test is completed successfully. |
|
With FALSE: An error has been detected during the method call-up.
An
In contrast to this, an
When you use the
|
|
The execution of the test is completed successfully (without any errors detected). A simple |
The methods Prepare
, Execute
and CleanUp
of a test case or a resource are called cyclically until an ASSERT
is evaluated to FALSE or TEST_DONE
is called. If a TEST_DONE
is called or if an ASSERT
is evaluated to FALSE, the execution of the method stops, cancelling the rest of the execution of the method.
If... |
Then ... |
---|---|
the execution of a test is ended via |
the test has been successfully completed. |
an assertion in the method |
the test case did not complete successfully. |
CleanUp
is evaluated to FALSE, the execution of the test is stopped. This is categorized as an error during initialization or de-initialization. A message is displayed in Logic Builder. It indicates that the test has been canceled and that a reset of the controller is required.
In the following program code example, the macros ASSERT
and TEST_DONE
are used in the implementation part of the Execute
method.
diResult := MyAdditionFunction(4, 3);
ASSERT(diResult = 7, 'MyAdditionFunction addition result not correct');
TEST_DONE();
In the following program code example, the macros ASSERT
and TEST_DONE
are used to test the function my_add
(a simple addition).
In the test case, a TestMyAdd
method was created. It is called multiple times by the Execute
method of the test case to test the function my_add
under different boundary conditions and with different parameters.
(* Methode Execute *)
(* Declaration part*)
METHOD Execute : PD_ETest.ET_TestReturn
VAR_INPUT
i_xFirstCall : Bool;
i_ifErrorLogger : PD_ETest.IF_ErrorLogger;
END_VAR
VAR_OUTPUT
q_rProgress : REAL;
q_sState . STRING[255];
END_VAR
VAR
END_VAR
(* Implementation part*)
ASSERT_SUBMETHOD (TestMyAdd(12, 2, 14, i_ifErrorLogger));
ASSERT_SUBMETHOD (TestMyAdd(12, 3, 15, i_ifErrorLogger));
ASSERT_SUBMETHOD (TestMyAdd(12, 4, 16, i_ifErrorLogger));
TEST_DONE();
(* Submethod TestMyAdd *)
(* Declaration part *)
METHOD TestMyAdd : PD_ETest.ET_TestReturn
VAR_INPUT
i_a : INT;
i_b : INT;
i_result : INT;
i_ifErrorLogger : PD_ETest.IF_ErrorLogger;
END_VAR
VAR
iResult : INT;
END_VAR
(* Implementation part *)
iResult : my_add(i_a, i_b);
ASSERT(iresult = i_result);
(* Function my_add *)
(* Declaration part *)
FUNCTION my_add : INT
VAR_INPUT
a : INT;
b : INT;
END_VAR
VAR
END_VAR
(* Implementation part *)
iResult : my_add := a + b;