Test coverage displayed within the editor
This article informs how the information on the test coverage is displayed within the appropriate editor. See "Executing the test" how you generate the information on the test coverage.
Displaying the test coverage within the editor
How to display the test coverage:
Open the tested POU as usual with the default editor (e.g. an ST-object within the ST-editor).
Within the ST- or FBD-editor, open the context menu and select the command Toggle Test Coverage. Alternative: Press Alt+Ctrl+C.
Within the LD-editor, click the element within the palette .
Result: The information on the test coverage is displayed within the editor:
Representation within the ST-editor
The background color of a line within the ST-editor informs about the test coverage of the code within the line:
Meaning of the background color:
green = fully covered
yellow = partially covered
red = not covered
If one statement consists of several lines as follows, the test coverage is only displayed for the first line of the statement:
More examples: See "Examples for a coverage in ST-editor".
It is possible that the information on the test coverage is not correctly generated for certain scenarios within the ST-editor. See "Restrictions on representing the test coverage within the ST-editor".
You can change these colors in the preferences: menu Window, Preferences, group General, Editors, Text editors, Annotations.
If you want details on the test coverage, best practice is to point onto the line or onto the icon left of the code.
Examples for a test coverage in ST-editor
Scenario for the examples: A POU with the input variable inputForTest is declared. There is a test case for this POU. This test case specifies a test sequence with the input value 0 for inputForTest.
The following examples result for test execution with test coverage:
ST statement |
Representation |
Explanation |
|
The full test coverage for an IF statement results from 2 branches:
Line with yellow background color – cause for the partial test coverage: The ELSE branch has not been executed. Line with green background color – cause for full test coverage: The →assignment has been executed. |
|
|
The full test coverage for a CASE statement results from 2 branches:
Line with yellow background color – cause for the partial test coverage: The ELSE branch has not been executed. Moreover, not all of the labels have been reached (due to the line with the red background color). Line with green background color – cause for full test coverage: The statements following the label 0,3,15..22 have been executed fully because the input value 0 is specified in the test sequence. Statements within a label are considered as fully covered, as soon as the statements have been executed at least once – even though additional values are specified within the label (here: 3,15..22). Line with red background color – cause for no test coverage: The statements following the label 55 has not been executed because only the input value 0 has been specified within a test sequence. |
|
|
The full test coverage for a WHILE statement results from 2 branches:
Line with yellow background color (with WHILE) – cause for the partial test coverage: Branch 1 has been executed, but branch 2 has not been executed due to the EXIT statement. |
Restrictions on representing the test coverage within the ST-editor
An incorrect test coverage is generated for the following scenarios. The result is the representation of a test coverage that does not match the actual test execution.
Scenario 1: The specified input value is used for the CASE level and for the condition within the included IF statement.
If a test is executed for the following function block FB1 and its test case specifies the input value 2 for Var1, a full test coverage is displayed for the line IF Var1 = 2 THEN.
But this representation of the full test coverage is not correct.
The branch
1, 2, 33..44
of the
CASE
statement
is only partially covered. The test case would have to contain an additional test sequence with a value ≠ 2 so that the CASE and IF statement are really fully covered.
FUNCTION_BLOCK FB1
VAR_INPUT
Var1 : INT;
END_VAR
VAR
x, y : INT;
END_VAR
CASE Var1 OF
1, 2, 33..44 :
x := 3;
IF Var1 = 2 THEN (* This line is displayed as fully covered in case of a test sequence with input value '2'. This display is incorrect. *)
y := 666;
END_IF;
END_CASE;
END_FUNCTION_BLOCK
Scenario 2: The specified input value is used for the CASE level, an IF statement is included within the CASE statement.
If a test is executed for the following function block FB2 and its test case specifies the input value 1 for Var2, a full test coverage is displayed for the line IF z = 3 THEN.
But this representation of the full test coverage is not correct. As the ELSE branch has not been executed, this IF statement is only partially covered. Even if the test case contains an additional test sequence with another value, the IF statement will never be fully covered because of the ST-logic.
FUNCTION_BLOCK FB2
VAR_INPUT
Var2 : INT;
END_VAR
VAR_OUTPUT
Result : INT;
END_VAR
VAR
x : INT;
z : INT := 3;
END_VAR
CASE Var2 OF
1, 2 :
x := 4;
IF z = 3 THEN (* This line is displayed as fully covered in case of a test sequence with input value '1'. This display is incorrect. *)
x := 6;
END_IF;
ELSE
x := 15;
END_CASE;
END_FUNCTION_BLOCK
Representation within the FBD-editor
Only the →calls of blocks are relevant for the test coverage within the FBD-editor. A partial coverage is only possible for calls of SEL blocks or of MUX blocks (see under Select functions) and for calls with a connected input EN.
An icon inform about the test coverage of the call:
= fully covered
= partially covered
A red icon for "not covered" is not applied in the FBD-editor.
See "Examples for a test coverage in FBD-editor".
Examples for a test coverage in FBD-editor
The call of the NOT block is fully covered.
Representation within the LD-editor
The contacts and the →calls of blocks (analogously to the representation within the FBD-editor) are relevant for the test coverage within the LD-editor.
An icon informs about the test coverage within the LD-editor as well:
= fully covered
= partially covered
= not covered