Skip to main content

Creating a Model-Based Test with a Test Table

The aim of a unit test is usually to determine the correct operation of a function block or program. You can formally implement the required test code as a test table.

Test script with IEC unit test and test table project

To create a unit test or integration test with just a little bit of programming skills, insert a test table into the test project. The test table editor helps you to create the test steps. One test step is mapped per row in the test table. You configure a row by defining an input assignment and the expected output assignment for the testee. In this way, you can programmatically access the interfaces of the testee, as well as those of the test application or the system. The aim is to fully test the testee. As a consequence, the minimum number of test steps results from the combinatorics of the input assignments.

The test script contains test cases which prepare the target system. Then the _tm_icon_iec_unit_test.png IEC Unit Test test element is called which triggers a mechanism to generate the actual test code.

Example: Examples.CounterTestTable

Tip

The CODESYS sample project CounterTestTable is included in the installation directory: C:\ProgramData\CODESYS Test Manager.

During the test run, the test table is implicitly converted into test POUs and used for creating a test application together with the testee. This is executed on the controller. When this is done, an evaluation is performed as to whether or not the test steps are maintained. An IEC unit test counts as passed when all test steps are performed without any errors. You can configure the error handling specifically for each test step. The results are saved as a report in the test repository.

Testee

The testee is a function block or program which is tested. In addition to its internal and external interfaces, system variables or global variables can be read.

If a function block (testee) is very complex, then it may be helpful to isolate it in sub-functionalities with its own function blocks and test them one after another.

Timeouts

Timeouts define maximum time spans for a test execution. If a timeout is exceeded, then the operation is aborted with errors. The remaining test POUs are executed. A test is structured hierarchically in a test table that contains test case groups, which in turn contain test cases. For this reason, there are timeouts for each of these levels.

. Timeouts in test tables
  • Global timeout of the test on the Global Information tab

    The global timeout applies over all test case groups and all test cases.

  • Local timeout of a test case group on the Tabular Editor tab

    A test case group can have its own defined timeout, which applies over all test cases of the test case group and overrides the global timeout. As a consequence, when this test case group is executed during the test run, its local timeout is used. The global timeout is invalid during that time.

  • Local timeout of a test case on the Tabular Editor tab

    A test case can have its own defined timeout, which overrides the local timeout of the test case group. As a consequence, when this test case is executed during the test run, its local timeout is used. The timeout of test case group and the global timeout are invalid during that time.

Tip

When you hover the mouse pointer over a test case group or a test case on the Tabular Editor tab, a tooltip shows its local timeout (along with other information).

Procedure. Defining a global timeout

Requirement: The test project has a test table.

  1. Click the test table.

  2. Select the Global Information tab.

  3. In the Timeout input field, specify a time period (in CODESYS time format).

    Example: T#5s

    The global timeout is 5 seconds.

Procedure. Defining a local timeout

Requirement: The test project has a test table.

  1. Double-click the test table.

  2. Click the Tabular Editor tab.

  3. Select the table row with the test case group or the test case.

  4. Click Test Table → Edit properties.

  5. In the Timeout input field, specify a time period (in CODESYS time format).

    Example: T#1s

    The local timeout is 5 seconds.

  6. Click OK to exit the dialog.

  7. Hover the mouse pointer over the edited table row.

    A tooltip opens and displays the timeout.

Duration

The duration determines the time and conditions of a single test step when it is executed. If they are not maintained, then the operation is aborted with errors and error handling is executed.

The duration is configured in the Duration column of the test table for each test step.

Options of the Duration column

  • Single: One-time execution of the test step

  • Cycles: Number of task cycles as long as the test step is executed

  • Time: Time as long as the test step is executed

  • _cds_icon_three_dots.png: Conditions under which the test step is executed

    Defined in the Custom conditions for duration dialog