Example 1: Test case for counter

This example illustrates how to create and execute a test for the following ST-code:

FUNCTION_BLOCK testCounter
VAR
/* If 'up' = 'TRUE', counter counts up. */
up : BOOL;
/* 'count' is incremented/decremented by '1' for each cycle. */
count : INT;
END_VAR
 
IF up THEN
count := count + 1;
ELSE
count := count - 1;
END_IF;
END_FUNCTION_BLOCK

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:

  1. Create the test suite for testCounter by using the command Create Test Suite. Details: See "Creating a test suite".
    Result: The test suite file testCounter.test and the Excel file testCounter.xlsm are created in the same folder as the ST-object.

  2. 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 for testCounter:
    images/download/attachments/449904880/TF_TestsuiteExampleCounter-version-1-modificationdate-1596023850243-api-v2.png
    The worksheet already contains the columns for the variables delivering the input data as well as the columns for the outputs (= expected results). As count is read from as well as written to, there are 2 columns for count.
    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:
    images/download/attachments/449904887/TF_TestsuiteExampleCounterModified-version-1-modificationdate-1596024065229-api-v2.png
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg 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.

  3. 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".

  4. 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.
    images/download/attachments/449904898/TF_TestsuiteExampleCounterConsole-version-1-modificationdate-1596024885192-api-v2.png
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg If error messages are displayed, a different version of logi.CAD 3 might be started and/or the application might have already been loaded onto the PLC.
    See "Executing the test" for the necessary steps.

  5. 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:
    images/download/attachments/449904902/TF_TestsuiteExampleCounterCoverage-version-1-modificationdate-1596025091125-api-v2.png
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg Actually, 2 test sequences in the test would have been sufficient for a full test coverage of the IF statement. See "Test coverage displayed within the editor" for details.