Automation of TwinCAT unit tests

Dear TwinCAT/PLC developers,

I’m very happy to announce the release of the TcUnit-Runner, an open-source tool for integration of TwinCAT unit tests into a CI/CD toolchain automation server such as Jenkins. When TcUnit, the TwinCAT unit testing framework, was released back in December of 2018 I would never have imagined how widespread it would get. Since then, I’ve received e-mails from PLC developers every week with questions, improvement suggestions or just gratitude for this open-source software. The TcUnit framework has found its way into the full range of projects ranging from small machines to multi-billion € projects. With this response, I would say that there definitely is a need for unit testing in the world of automation. The adoption of TcUnit into TwinCAT projects across the globe has motivated the further development of TcUnit. One limitation of the TcUnit framework was that it was only possible to run the unit tests locally on your development machine (or PLC), and thus needed to be run manually every time a change in the software was made. Modern software practices advocate that software development should adhere to the practices of continuous integration/continuous delivery (CI/CD), so that tests would be run automatically when committing changes to version control. Thus, TcUnit-Runner was developed.

TcUnit-Runner is an open-source software that makes it possible to integrate TwinCAT unit tests in a CI/CD software such as Jenkins.

Concept of TcUnit-Runner


Example of TwinCAT unit test job in Jenkins

With Jenkins and a version control system (such as Git or SVN), it’s possible to automatically run all unit tests in a TwinCAT project automatically if a TwinCAT project is changed in the version control system. All test results are automatically generated and reported in standard xUnit/JUnit XML format which Jenkins natively supports.

The software is released as version 0.9 and hopefully this software and the documentation will receive feedback for a 1.0 release in the coming weeks. With the release of this software my hope is that it facilitates the adoption of modern software development practices among PLC developers. As always, all software is open-source and MIT-licensed, which means it can be used freely for non-commercial and commercial re-distribution, whether in source or binary form. I hope that TwinCAT developers will make use of this software and provide feedback so that it can constantly evolve. As of today, a dozen people have contributed to the project.

Want to get started?

Go to the user manual, which includes an introduction, a quick start and a full example.

Want to access the source code and/or contribute to the project?

Please visit the GitHub project page.

If you are completely new to unit testing in general and unit testing in TwinCAT/PLCs in particular I recommend reading the:

  1. Core concepts of unit testing
  2. Introduction user guide to TcUnit (the TwinCAT unit testing framework)
  3. TcUnit website
  • Share on:

6 Comments, RSS

  1. David

    Really appreciate the work put into this! Will be trying to integrate this into an Azure CI/CD pipeline very soon

  2. Ivana

    Hi! I am very excited about this new tool, I already created something similar myself with help of your static code analysis example. However, when I am trying to use TcUnitRunner with Jenkins, it seems to always hang after successfully loading the VS DTE. Any ideas why?

  3. Christoph

    First of all, I would like to thank you for the great blog and the great tooling that makes PLC development much more enjoyable!

    So far I have used the TcUnit-Runner locally and plan to use it in a CICD infrastructure soon.
    Unfortunately, I am new to C# programming and I am not sure if it is possible to install/deploy the runner automatically and if it is possible, how I can implement this in my pipeline.
    My goal would be to manage the runner installation using IaaC, would that be possible?

    Best regards,

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.