Industrial automation developers looking to integrate AI into their PLC workflows now have a viable path for automated unit testing in CODESYS. A recent deep dive by developer Zhou Yongh outlines a framework where AI agents generate standard Structured Text (ST) tests that run directly within the PLC environment. This method bypasses the traditional bottlenecks of black-box host testing and unmaintained community libraries, offering a practical solution for verifying logic on SoftMotion Win 64 and Windows platforms using CODESYS V3.5 SP17.
The Problem With Existing Solutions
Unit testing in CODESYS has historically been a fragmented landscape. Zhouโs analysis critiques current approaches, noting that host-side pytest drives are too far removed from the field and suffer from nondeterministic timing. While tools like Matiec offer offline compile checks, they fail to cover axis control or online state. Commercial solutions like the CODESYS Test Manager are robust but often restricted in OEM environments, and community libraries like CoUnit frequently require installing dependencies directly onto the PLC, a practice many engineers avoid to maintain runtime stability.
An xunit-Inspired Architecture
The proposed solution adopts a zero-dependency philosophy on the PLC side, modeling its structure after xunit frameworks. Test suites are implemented as function blocks (FB_
Practical Implementation and Caveats
While the architecture is elegant, Zhou warns of strict versioning requirements. The project, CODESYS, and run-target must align precisely, with specific attention paid to the SoftMotion Win V3 x64 device type. Developers must ensure that PRG_Tests is attached to a cyclic task and that the g_uiSuitesTotal variable matches the actual number of suites. Furthermore, the host connection requires a download command to load new logic, as a simple login is insufficient. Security best practices dictate using environment variables or -UserFile parameters rather than committing passwords to source control.
Key Takeaways
- AI can generate standard ST code that functions as unit tests without requiring PLC-side library dependencies.
- The framework supports multiple result formats, including JUnit XML, facilitating integration with existing CI/CD pipelines.
- Strict version matching between the IDE, runtime, and hardware is critical for successful execution.
- Assertions are white-box, running in the same cycle as the logic under test for precise timing accuracy.
The Bottom Line
This zero-dependency, xunit-inspired approach is the most pragmatic step toward AI-assisted PLC development, effectively eliminating the runtime stability concerns that have stalled automated testing in industrial environments for years.