Basic Functionality of the IEC Unit Test
Definition of test cases
The test cases of IEC unit tests are executed directly on the controller, in contrast to test cases in a test script.
This makes it possible to write test cases which call the testee in a cycle-consistent manner, and as a result provide exact timing. The full IEC language scope is available for the test.
An IEC unit test always requires a test project as an execution framework, in which the test cases are defined in IEC. A test project for the IEC unit test always has to contain an application with the name Application and an empty POU PLC_PRG (type: Structured Text). An application or device object with the name Backup must not exist because this will be created implicitly later.
The test cases are always IEC function blocks according to a template or are generated as such (when using the test tables). All function blocks are currently edge-triggered (like an
ETrigA
). There are different templates/types of test case function blocks. These are described in the following chapters. Templates and the Input Assistant are available for writing the POUs.The test cases are grouped together in the test project and have to be defined in one of the following locations:
Below the Application application
In the POU pool
In a library which is referenced by the test project in the Library Manager of the Application application or the POU pool
Configuration of the execution of test cases
A test script is always required to execute the IEC unit test – it is the entry point of any IEC unit test.
Requirements:
The test script has to contain suitable test actions to load and configure the test project in the first place:
Loading a project
Set the device object of the Application application to match the target device (device description)
Set the communication of the device object to the target device
Prepare target device, if necessary (for example, delete any existing applications there, set the user management)
The test script has to contain an element of type IEC Unit Test. Details about the selection and execution of the test cases can be entered there.
Execution procedure
The user starts the test script.
The test script prepares the test project.
The IEC unit test element in the test script is processed:
Search all test case function blocks which can be found in the project.
Filtering the test case function blocks based on the entered selection
Generating the instances and calls of the test case function block in
PLC_PRG
of the Application applicationCreating the backup (application or device)
Downloading the application to the target device. According to the respective interface convection, the execution of the test case function blocks is triggered and queued until they are finished
Reading the results of the test case function blocks from their outputs
Generate a test report with the results
At the end of the execution, the test project remains in this state with the generated calls of the test case function blocks. This state is suitable for debugging errors in the test with CODESYS: To do this, the user has to manually log in and trigger the test case function block in question.