Automated PLC Testing

PLC Test Harness
TDD for Industrial Automation

Define test scenarios, execute them against PLCSim Advanced, and get instant PASS/FAIL verdicts. Unit testing for PLC logic — the same way software engineers test their code.

PLC Testing Is Still Manual

Every code change is a gamble without automated tests

No Regression Testing

You modify a function block and pray nothing else breaks. Without automated tests, every change risks introducing silent bugs that only surface on the factory floor.

Manual Verification

Testing means manually forcing inputs on the PLC or PLCSim, watching outputs change, and checking values by hand. Tedious, error-prone, and impossible to repeat consistently.

No Test Documentation

How do you prove your program works correctly? Test procedures exist in Word documents or an engineer's head. No standardized, executable test specs that travel with the project.

AI Can't Verify Its Own Code

AI generates PLC code, but how do you know it works? Without automated testing, AI-generated code goes untested into production. The Test Harness closes the loop.

How PLC Test Harness Works

A structured test framework for PLC logic, accessible via MCP, Copilot and REST API

Define Test Scenarios

Each test is a sequence of steps: set inputs, wait for the PLC to react, then verify outputs match expectations. Tests are stored as .test.json files alongside your TIA Portal project.

4 Assertion Types

Exact match for booleans and integers. Tolerance for floating-point values (±0.1). Range for min/max checks. Not-equal to verify a value has changed. Covers every PLC data type.

Setup & Teardown

Each test starts with a setup phase (initialize tags to a known state) and ends with teardown (reset tags to zero), even if the test fails. Clean state guaranteed.

Run One or Run All

Execute a single test by name, pass a test inline, or use wildcard (*) to run the entire test suite. Results are stored in last-results.json for review.

Full Audit Trail

Every test run produces a detailed report: which steps passed, which failed, expected vs actual values, and execution timestamps. Export or query results anytime.

AI-Driven TDD Cycle

A connected LLM can write code, create tests, compile, download to PLCSim, run tests, and fix failures — all autonomously. Red → Green → Refactor, for PLC.

The TDD Cycle for PLC

From test definition to validated PLC logic

1

1. Write the Test

Define expected behavior: when Start_Button is pressed, Motor_Running should be true within 500ms. Create the test with plc_test_create.

2

2. Run Against PLCSim

Execute the test with plc_test_run. T-IA Connect writes inputs to PLCSim, waits the specified delay, then reads and checks outputs. Verdict: PASS or FAIL.

3

3. Fix & Iterate

If a step fails, you see exactly what went wrong: expected Motor_Running = true, got false. Fix the PLC program, recompile, download, and run the test again.

4

4. Build Your Test Suite

Accumulate tests as you develop. Run the full suite after every change to catch regressions. Tests travel with the project in .tia-connect/tests/.

Assertion Types in Detail

Covering every PLC data type with the right comparison

Exact Match

For booleans and integers. Motor_Running must be exactly true. Counter must be exactly 5. No margin for error.

Tolerance (±)

For REAL and LREAL values. Speed must be 50.0 ± 0.1. Accounts for floating-point precision and analog measurement noise.

Range (min/max)

Value must fall within a defined range. Temperature between 10.0 and 100.0. Perfect for analog inputs and process values.

Not Equal

Verify that a value has changed from its initial state. Counter must not equal 0 — confirming the counting logic actually ran.

5 Tools Across 3 Channels

Available via MCP, Copilot (built-in assistant), and REST API

plc_test_create

Save a test case definition with setup, steps (inputs → delay → assertions), and teardown. Stored as a .test.json file in .tia-connect/tests/.

plc_test_run

Execute a test by name, pass one inline, or use * to run all tests. Asynchronous via REST (returns a jobId). Results saved in last-results.json.

plc_test_list

List all saved test cases with their names and descriptions. Quick overview of your project's test coverage.

plc_test_delete

Remove a test case by name. Clean up obsolete tests as your project evolves.

plc_test_get_results

Retrieve the latest test run results: per-step PASS/FAIL status, expected vs actual values, execution time, and overall verdict.

Frequently Asked Questions

Does this require PLCSim Advanced?

Yes. The Test Harness writes inputs and reads outputs via PLCSim Advanced's simulation interface. It doesn't work with real PLCs (that would be dangerous for automated testing). PLCSim Advanced provides a safe, repeatable environment.

Can an AI create and run tests autonomously?

Absolutely. A connected LLM (via MCP or Copilot) can write PLC code, create a test with plc_test_create, compile and download to PLCSim, run the test, check results, and fix the code if it fails. Full TDD cycle without human intervention.

Where are the tests stored?

In the .tia-connect/tests/ folder next to your TIA Portal project. Each test is a .test.json file. Results are in last-results.json. Tests travel with the project — archive the project, archive the tests.

How long does a test run take?

It depends on the delays you define in your test steps (the time you give the PLC to react). A typical test with 3-5 steps and 200-500ms delays runs in 1-3 seconds. Running a full suite of 20 tests typically takes under a minute.

Test Your PLC Code Like Software

Automated testing, regression detection, and TDD — everything software engineers take for granted, now for TIA Portal PLC programs.