Examples

A sample project for the TF1140 is available on the Beckhoff GitHub at the following link: TF1140-Sample

This example shows a simple library that provides function blocks for basic arithmetic operations. In the function block for addition (FB_Sum), an error has been intentionally introduced for this purpose (subtraction occurs instead of addition).

Set-up of the example:

Examples 1:

The example contains a TwinCAT project. Two PLC projects are stored in it. The former is the actual library (SampleLib), which is being developed and will therefore be tested in this example. This is marked with the property “Allow the project to be referenced as a library,” which has been available since TwinCAT version 4026.

Examples 2:

This option makes it possible to use this library in the same TwinCAT project without first installing it on the system. This simplifies testing, especially in CI/CD pipelines, since it eliminates this additional step.
To take advantage of this, it makes sense to manage the test project for this library within the same TwinCAT project, as shown in the example. This ensures that the source code for the library and for the tests is managed in the same source code repository and is therefore up to date.

In the test project itself, the library to be tested must be implemented accordingly. Referenced libraries are represented in the library management interface with square brackets and in the project itself with a slightly darker icon.

Examples 3:

In addition to the library to be tested, the Tc3_PlcTestFramework library must be implemented. This is included with the test framework installation and contains the necessary base classes and function blocks, as well as the interface to the test clients (see the chapter Technical introduction).

Under the "TestCases" folder in the UnitTest PLC project, you will find the individual test function blocks; the corresponding blocks are located in the PLC library. These must be instantiated in the main program. In the Main-POU body, the test controller function block–which provides the interface to the test clients–must be called. To run the tests, follow the instructions in the chapter Quickstart.