Unit testing for TIA Portal
TIA Portal unit tests for SCL blocks
Write, run and evaluate SCL unit tests for your TIA blocks, against PLCSIM Advanced or real hardware, with AI authoring and CI/CD.
TIA Portal V15-V21 · PLCSIM Advanced · S7-1200/1500 · from Pro+
The Test Suite Editor of FB_ConveyorControl_Tests lists all 12 test cases of FB_ConveyorControl as rows. The new case Overload_ShortPeak_NoTrip gets a description, the input rMotorCurrent = 14.0 and two assertions picked from the operator list: bOverloadFault Is False and bMotorRun Is True. Run Case runs it against PLCSim Advanced and the case passes, so all 12 cases are green.
What SCL unit testing in Studio does
Arrange, act, assert without code
Set inputs, let the PLC cycle, check outputs: in the visual editor, as JSON or as generated SCL.
PLCSIM Advanced or real S7
Against a virtual PLCSIM Advanced instance or straight against a real S7-1200/1500.
The AI writes the suite
The assistant derives test cases with boundary values from the block interface.
CI/CD with JUnit XML
The command-line runner works in GitLab, Jenkins and co. and writes JUnit XML and HTML.
Contents
A unit test in TIA Portal checks a single PLC block (FB/FC) in isolation: write defined inputs (Arrange), let the controller run a few cycles (Act) and check the outputs against expected values (Assert). The test runs against PLCSIM Advanced or a real S7 PLC, automated, repeatable and in CI/CD. The test cases can come from the AI assistant on the TIA Portal AI page; how AI fits into PLC programming as a whole is in the guide AI for PLC programming.
How does an SCL unit test work?
AnyAutomation Studio reads your block's interface straight from the TIA project so inputs and assertions validate against the real parameter names and types. A test suite is a .tia-tests/*.json file next to your project file. Each test case follows Arrange → Act → Assert: write values, wait cycles, check results. The runner creates the PLCSIM instance, compiles, connects, writes inputs, reads outputs and evaluates the assertions.
Against PLCSIM Advanced or real hardware
By default a suite runs against a PLCSIM Advanced instance (V3.0 or later): fast and without physical hardware. Via S7 Native or OPC UA you test straight against a real S7-1200/1500. A safety prompt appears before every run on real hardware, and the runner checks the controller is in RUN before it writes. Full configuration is in the unit testing documentation. After the test, the agent can watch the same block on the running controller with the OPC UA client with AI.
In the PLCSim Advanced dashboard you create a simulation instance PLC_1 with a CPU 1516 at 192.168.10.20, power it on and switch it to Run. In the tag browser you read, write and watch the tags of idb_ConveyorControl: setting bStart to TRUE starts the conveyor motor and the motor current is set to 6.4.
Test cases, history and working without TIA Portal open
You create test cases in the visual editor, as JSON or as generated SCL. More than 20 assertion operators are available, and a test case can consist of several steps: write, wait, assert. The AI assistant derives complete suites with boundary values from the block interface, editable right in the chat.
Every run is stored: you compare runs, spot unstable tests and follow the pass rate over time in trend charts, with CSV export. For the pipeline, the tia-test-runner command-line tool writes JUnit XML and HTML reports, more on that in CI/CD for TIA Portal.
You can write and run tests without keeping the TIA Portal window open: the interface then comes from an exported copy. Paths are never stored in plain text, so you can check suites in without secrets.
Studio vs. Siemens Test Suite
Siemens Test Suite (Advanced) is deeply integrated into TIA Portal and strong for certified acceptance workflows. AnyAutomation Studio takes a different angle: lightweight, scriptable SCL unit tests that fit your version control and CI/CD: Git diffs of the suites, AI-authored cases, trend reports and a command-line runner for the pipeline. If you want to test PLC code like software rather than sign off once, that is the difference. See also TIA Portal Test Suite alternative.
Frequently asked questions
What is a unit test in TIA Portal?
A unit test checks a single PLC block in isolation following Arrange/Act/Assert: set inputs, let the controller cycle, check outputs against expected values, against PLCSIM Advanced or a real S7 PLC.
Can I test against real S7-1200/1500 hardware?
Yes. Over an S7 Native or OPC UA connection a suite runs straight against the real controller. A safety prompt appears before the run, and the runner only writes when the PLC is in RUN.
Do I need an extra Siemens license for unit tests?
For PLCSIM Advanced runs you need a PLCSIM Advanced license from Siemens. The SCL unit testing itself ships with AnyAutomation Studio from the Pro+ tier, no Test Suite Ultimate license required.
Does it run in CI/CD?
Yes. The tia-test-runner command-line tool runs suites in GitLab CI, Jenkins and similar pipelines and produces JUnit XML and HTML reports. --rerun-affected runs only suites whose block changed.
Can AI write PLC unit tests?
Yes. The AI assistant derives test cases and boundary values from the block interface and writes them into the .tia-tests folder, editable straight from chat. Review the expected values like any other code: a language model can propose a wrong assertion, so a failing test is a question for an engineer, not an automatic verdict.
Can I unit test without PLCSIM Advanced?
Yes, against a real S7-1200 or S7-1500 controller. Some controller has to execute the block, either PLCSIM Advanced or hardware.
Which plan includes unit tests?
SCL unit testing is included from the Pro+ plan (CHF 50 per month or CHF 550 per year); the AI chat that writes the suites is included from Basic. A step-by-step introduction is in the SCL unit test tutorial.
Try it now
Try SCL unit testing yourself
Try AnyAutomation Studio free for 30 days, no credit card. For TIA Portal V15-V21 and CODESYS 3.5.
Free account required: sign in with your email address and a code, then the download starts.
Questions? support@anyautomation.ch