Table of Contents

In-solution test PLC (TcUnit)

Use this layout when the TcUnit application is a second PLC in the same TwinCAT solution as the library or application under test. You maintain the suites yourself (FB_TestSuite, TEST() / TEST_FINISHED(), TcUnit.RUN() in MAIN). Nothing is generated under tests/.

zkmake and zkbuild-action both run this layout. Twinpack marks the PLC as UnitTestApplication when the PLC has a task and references TcUnit. You can also set "type": "UnitTestApplication" in the main config.json.

Run these suites by activating the test PLC, in the IDE or in CI. DataRows, --test-framework, and Test Explorer belong to embedded tests.

Other layouts, result files, and CI reporting: Unit tests.


Repository layout

The test project is a normal .tsproj / .plcproj in the repository, included by the same .sln as the code under test. It is not placed under tests/.

my-repo/
├── .Zeugwerk/
│   └── config.json          ← library and test PLC (type: UnitTestApplication)
├── MyLibrary.sln
├── MyLibrary/
│   └── MyLibrary.plcproj
└── MyLibraryTest/
    ├── MyLibraryTest.tsproj
    └── MyLibraryTests/
        └── MyLibraryTests.plcproj

config.json

Add the test Visual Studio project under projects. The PLC type is UnitTestApplication. Declare TcUnit (or TcUnit_Zeugwerk) under packages, and reference the library plus the usual system libraries.

{
  "name": "MyLibraryTest",
  "plcs": [
    {
      "name": "MyLibraryTests",
      "version": "1.0.0.0",
      "type": "UnitTestApplication",
      "packages": [
        {
          "name": "TcUnit",
          "version": null,
          "distributor-name": "www.tcunit.org"
        }
      ],
      "references": {
        "*": [
          "Tc2_Standard=*",
          "Tc2_System=*",
          "Tc3_Module=*",
          "[MyLibrary]=*"
        ]
      }
    }
  ]
}

The test project belongs to the solution named at the top of this config.json.

Suites look the same as in a separate test solution: extend TcUnit.FB_TestSuite (or TcUnit_Zeugwerk.FB_TestSuite), and call TcUnit.RUN() from MAIN. The library reference can be the project in this solution ([MyLibrary]=*) instead of a restored package.

What the build does

During the release build:

  1. Patches TcUnit parameters on the test .plcproj (xUnit result path, buffer sizes, and the suite/test/assert limits).
  2. Assigns an isolated CPU core on the target given by --netid / the cloud target.
  3. Compiles the whole solution, including the test application, with headless TcXaeShell.

During the test phase the built boot project is deployed and JUnit XML is collected from that project. Results are written to tests/<TestProjectFolder>/TcUnit_xUnit_results.xml (archive/tests/<TestProjectFolder>/ in the cloud). <TestProjectFolder> is the directory of the test .tsproj.

No harness is generated. --test-framework is ignored. The TcUnit package declared in config.json is the one that runs.

When this layout is used

This path runs when the repository has no embedded IUnitTest function blocks and no tests/.Zeugwerk/config.json. Either of those takes over:

There is no DataRow generation for this layout.