I’m very happy to announce the release of TcUnit – an unit testing framework for TwinCAT3. TcUnit is an xUnit type of framework specifically done for Beckhoffs TwinCAT3 development environment. This is another step in the direction of modernizing the software development practices in the world of automation.
Before dwelling into the details, let me tell the background of this project. In 2016 the development of the CorPower wave energy converter (WEC) was in an intensive phase. Software was being finalized, tested and verified for delivery. In a late phase of the project some critical parts of the software needed to be changed. The changes could be isolated to a few function blocks (FB), so in an initial phase the tests simply consisted of exporting those FBs to a separate project and running them locally on the engineering PC. The FBs were changed and executed in the engineering environment, and then online-changing the inputs and seeing whether the expected outputs were given. After doing this for a couple of hours an important question was raised:
Shouldn’t this be automated?
What we were basically doing (without thinking about it) was specifying unit tests. The inputs were our test fixtures, and the outputs were our test results. We (manually) checked (asserted) whether the results were according to our expectations/specification. Because we were doing this manually, it was a one-time shot and if we wanted to check the results again we had to do the test again which was very time consuming. The knowledge we had gained by doing the tests was lost as it was not documented anywhere. We tried to find an unit testing framework for TwinCAT, but none was found. The approach of test driven development and unit testing was not something that was lacking in particular for TwinCAT, it seemed to be the same situation in the world of automation in general. It was at this moment in time we realized we needed to create our own framework to write and run our tests in so that we could do unit testing of any new TwinCAT software. We simply could not afford not to do unit testing. Everyone (outside of the world of automation) is doing unit testing. Select any programming language (C++, Java, Python, …) and there are numerous unit testing frameworks available. There is no reason for why the world of automation should not be able to do test driven development!
Fast forward to now, and I’m currently working on the ESO extremely large telescope. It’s a fantastic piece of engineering, with a variety of programming languages and systems. It’s truly a cathedral of science that I’m proud of being part of!
The amount of software required for the ELT is going to be ginormous, and naturally the amount of PLC software will follow the trend of more complexity. The time where PLC software is seen as something “living in its own world” separated from the rest of the software development processes is almost gone. Now it’s time to demonstrate that PLC software development too can adhere to modern software practices and being part of the standard software development life cycle and pipeline. This is a good moment in time to package all the loose software that the framework consisted of into one package.
Now on to the framework itself. The framework is easy to use. All that is needed is to download & install the library and provide a reference to the TcUnit-library in your project, and you can start to write your test code. For a complete set of instructions, read the unit-testing concepts, followed by the introductory user guide and finish with the example. You can either download a precompiled version of the library or download the source code. The library and all the source code is licensed according to the MIT-license, which has one of the most relaxed software license terms. The software is completely free, and you can use the software without restrictions, be it private or for commercial use. Want to modify the source code for some reason and create your own library out of it? No problem, the MIT-license is very permissive.
This is only the first step. The framework (and accompanying documentation) will be updated with more functionality in the coming months. On short term, see the issues on the GitHub-page. On longer term, the next step is to release software that integrates the framework into an automation server (such as Jenkins), so that it’s possible to have a job running and executing the tests automatically (based on some user-defined criteria), adhering to continuous integration and delivery. I’m certain that there are many TwinCAT developers out there already doing this! My hope is that there are others out there that will get use of this, and even possibly contribute to the project, by for example correcting bugs or giving feedback and improvement suggestions. There is a lot to win to have software development driven by a community.
Main site is available on:
Unit testing… what’s that?
Read the core concepts.
Want to know how to get started?
Read the user guide: https://tcunit.org/introduction-user-guide/
Want to see a more advanced example?
Read the seven chapter programming example:
– Chapter #1: https://tcunit.org/programming-example-introduction/
– Chapter #2: https://tcunit.org/programming-example-the-function-blocks/
– Chapter #3: https://tcunit.org/programming-example-test-cases-part-one/
– Chapter #4: https://tcunit.org/programming-example-test-cases-part-two/
– Chapter #5: https://tcunit.org/programming-example-implementation-part-one/
– Chapter #6: https://tcunit.org/programming-example-implementation-part-two/
– Chapter #7: https://tcunit.org/programming-example-final-words/
Want to download a precompiled (ready to use) version of the library?
Go here: https://tcunit.org/download/
Want to download the source code?
It’s available on GitHub: https://github.com/tcunit
Want to dive into the application programming interface?
Here you go.
Want to download example code of how to use TcUnit?
Simple example: https://github.com/tcunit/ExampleProjects/tree/master/SimpleExampleProject
Advanced (more realistic) example: https://github.com/tcunit/ExampleProjects/tree/master/AdvancedExampleProject
CorPower WEC – CorPower Ocean
Extremely large telescope – ESO/L. Calçada
I would like to say a huuuge Thank you! for this article.
I am very happy to find a website like this, and to find somebody who has the same problems/thinking and software development attitude like me, because it is unfortunately not that common in the industry yet.
I am happy, that these software development practices are getting more interest and that PLC developing(mainly with Beckhoff) becomes something much more efficient and modern thanks to these things.
I am reading your articles very happily and interested, and I will definitely try this unit testing and it’s capabilites.
Keep up the articles, this is good stuff!
I just want to express my best wishes and congratulations for the forum.
I have just started developing software with PLCs and I admit there is little material online, especially for novices.
As a software engineer I really appreciate the software oriented approach and the open source community.
I hope this great service will continue over time and maybe, in the not too distant future, I can help improve it.