Example 5: Test case for addition with initial value of a local variable
This example illustrates how to create and execute a test for the function block testAddition_InitialValue
provided by the following ST-code:
|
In contrast to example 3, the function block testAddition_InitialValue
contains an →initial value for the local variable VAR1
that is to be considered during the test.
The procedure of how to test this function block is analogous to the previous examples. Hence, this procedure is not listed in this example again. Instead, this article concentrates on the action to be done in the test suite that are required for the initial value.
Likewise to example 3, the created test suite contains these pieces of data:
-
The worksheet
Defaults
contains the following data:-
VAR1
with value0
and test modeuseTestValue
-
IN1
andIN2
with value0
and without a test mode (The test mode is not relevant for input variables.)
-
-
The worksheet for the test case contains these columns:
-
IN1
-
IN2
-
VAR1
-
OUT
-
For the initialization value 20
from the application to be taken into account during the test, you must adapt the test suite as follows:
-
In the worksheet
Defaults
, make these changes forVar1
:-
Delete the predefined value so that the column
Default Value
does not contain any value forVar1
. -
Enter this test mode:
useImplValue
-
-
In the worksheet for the test case, delete the column
Var1
.
As usual, also enter the test sequences and test data in the worksheet for the test case. Here, the expected result for the test sequences must take into account the initialization value 20
for Var1
(so that the test case is executed successfully).
If you execute this test case, the console will display PASS
as a result of the test execution. Reason: Because of useImplValue
(and the missing data for Var1
), the initialization value 20
for VAR1
from the application is used in the addition – for both test sequences.
Hence, these calculations result are true:
-
Addition:
1 + 2 + 20 = 23
-
Addition:
1 + 3 + 20 = 24