Example 1: Test case for counter
This example illustrates how to create and execute a test for the following ST-code:
|
This ST-code is the one of the program Counter
that is created by using the sample project for the built-in PLC Counter (ST). Due to the restrictions for programs, the ST-code has been copied to a function block.
How to test the above function block testCounter
:
-
Create the test suite for
testCounter
by using the command Create Test Suite. Details: See "Creating a test suite".
Result: The test suite filetestCounter.test
and the Excel filetestCounter.xlsm
are created in the same folder as the ST-object. -
Open the Excel file, enter the test data in the existing worksheet
test testCounter
and save the modified Excel file.
Here the worksheet as it has automatically been created fortestCounter
:
The worksheet already contains the columns for the variables delivering the input data as well as the columns for the outputs (= expected results). Ascount
is read from as well as written to, there are 2 columns forcount
.
You decide how many test sequences and which test data you define for the test. This example uses the following test sequences and test data:
The Excel file also contains other worksheets that are not used in this example. See "Structure of the Excel test suite, modifying the worksheets" for information on these worksheets. -
Transfer all test data from the Excel file to the test suite file
testCounter.test
by importing the Excel file. Details: See "Create the test suite based on the Excel file for the test execution". -
Have the tests executed, e.g. run a SiL-test with coverage. Details: See "Executing the test".
Result of the test execution: The console displays the progress and the result of the test execution.
If error messages are displayed, a different version of Neuron Power Engineer might be started and/or the application might have already been loaded onto the PLC. See "Executing the test" for the necessary steps. -
Check the test execution. Details: See "Checking the test execution".
In case of a SiL-test with test coverage, you are able to have the test coverage displayed within the editor. The following test coverage is displayed for the example:
Actually, 2 test sequences in the test would have been sufficient for a full test coverage of theIF
statement. See "Test coverage displayed within the editor" for details.