Behavior over structure
Different ladder or Structured Text implementations can satisfy the same requirement. Grade the observable behavior unless a specific architecture is itself required.
A program is not tested because the editor shows green contacts or a motor moved once. Testing turns a control requirement into repeatable stimuli, timed observations and a pass or fail verdict—across normal operation, boundaries, faults, resets and restarts.
Product evidence: every simulator scenario can define multiple executable test cases with input actions, waits, pulses, output assertions, physics-state assertions and timeouts. Each case starts from fresh state before the aggregate verdict is issued.
State the observable control behavior and the conditions under which it must hold.
Apply a precise input sequence, duration, fault or process event from known initial state.
Sample outputs, sequence state, timing and physical-model response at useful boundaries.
Compare against explicit acceptance criteria and retain enough evidence to reproduce a failure.
The strongest test is readable by a programmer, commissioning engineer and reviewer: each can see what was required, what was applied and why the result passed.
Answer first
PLC program testing is the systematic verification that control logic produces required outputs and state transitions for defined input sequences. It includes more than a compile check or online observation. A useful test begins from a known state, applies realistic and adversarial conditions over scan time, checks observable acceptance criteria, and records which requirement passed or failed. Simulation is one layer; target-controller tests, I/O proving and controlled commissioning remain separate layers.
Different ladder or Structured Text implementations can satisfy the same requirement. Grade the observable behavior unless a specific architecture is itself required.
Timers, latches, counters and process physics can contaminate the next case. Reset or reinitialize before each independent requirement.
A red verdict should identify the failed condition, actual value and reproduction sequence so the programmer can diagnose rather than guess.
Reproducible cases
The minimum useful format is Given–When–Then, expanded with time because a PLC is a cyclic, stateful system interacting with a changing process.
Clear runtime, process model, overrides and test history to a documented baseline.
Establish mode, permissives, sensor states and any required precondition.
Pulse a button, change an input, wait a duration or inject a physical event.
Check outputs, internal state where justified, timing, alarm and recovery results.
Reset is shown as a first-class phase because old latch, timer, counter or physics state can make an otherwise correct assertion meaningless.
Start with a requirement stated in observable language. “The rung should seal in” describes an implementation. “After a valid start pulse, the motor command remains true until Stop, overload or emergency stop becomes active” describes behavior. The second statement can test a seal-in branch, a SET/RESET implementation or a Structured Text state variable without confusing one drawing style with the real acceptance criterion.
Define the initial state. The machine mode, permissives, timer values, counter values, physical position and fault latches all matter. If the test relies on a prior case having left the conveyor running, then it is a sequence of dependent steps and should be written as one scenario. Independent requirements should start clean. Fresh state prevents a passing first case from donating a latched bit to a broken second case.
Apply inputs with durations that the scan can observe. A pushbutton pulse shorter than the task interval may be missed on a real controller unless hardware or input buffering captures it. In simulation, a pulse should span enough scan steps to establish an on edge and a later off edge. A wait should describe why it exists: allow a timer to complete, let physics settle, or confirm that an output remains stable.
Assert what matters to the requirement. An output bit may be enough for simple combinational logic. A sequencer may require phase, actuator command and process-state evidence. Avoid asserting every internal tag simply because it is visible; that overfits tests to one implementation and makes safe refactoring expensive. Assert internal state only when the state is part of the design contract or needed to prove a hazardous transition cannot occur.
| Field | Question it answers | Weak version | Strong version |
|---|---|---|---|
| Requirement | What must the controller do? | Motor works | Start pulse latches run command while all listed permissives remain true |
| Initial state | What is true before the action? | Default | Auto mode, guard closed, overload clear, motor stopped, no forces |
| Stimulus | What changes and for how long? | Press Start | Set Start true for 100 ms, then false; advance three 50 ms scans |
| Observation | Which evidence is sampled? | Looks right | Motor command, run feedback expectation and alarm state |
| Verdict | What exact result passes? | No error | Command true after pulse; false within one scan of Stop |
Test selection
A happy-path test shows that the design can work. The rest of the matrix shows whether it fails and recovers in the intended way.
Valid commands and process changes produce the intended sequence and outputs.
Thresholds, timers, counts, tolerances and simultaneous inputs behave at their edges.
Lost permissives, bad feedback and abnormal process values reach a defined safe state.
Reset, re-entry, power-up and mode changes do not create an unintended restart.
The families are a planning tool, not a fixed test count. Risk, state complexity and machine consequences determine how many cases each family needs.
Normal cases should include more than one convenient combination. For a motor circuit, prove start, maintained run, stop and repeated cycling. For a sequence, prove the complete route and the handoff between each phase. For analog control, exercise more than one process region. These cases establish the intended path and provide a fast regression set after changes.
Boundary tests sit immediately below, at and immediately above a decision point. A high alarm at 90 percent needs evidence at the raise boundary and the clear boundary if hysteresis exists. A five-second TON needs checks before and after completion at the task resolution. A counter needs zero, preset minus one, preset and rollover or saturation policy. Simultaneous Start and Stop inputs also form a boundary because rung order and priority decide the result.
Fault tests remove or contradict something the normal path assumes: overload trips while running, feedback never arrives, a sensor remains stuck, communications quality fails, or two mutually exclusive limits are true. The expected outcome includes the safe output state, diagnostic or alarm, and whether an automatic retry is allowed. A fault test that only checks “motor off” misses the reason and recovery contract.
Recovery tests begin after the abnormal condition. Removing a cause is not always the same as acknowledging an alarm or issuing a reset. Prove the required sequence and ensure a reset cannot bypass an active cause. Restart tests cover cold start, warm restart and return from mode changes where relevant. A controller that resumes motion because a retained run bit survived power loss can pass every ordinary start/stop test and still be unacceptable.
Cyclic execution
PLC logic evolves over scans. Input image timing, rung order, function-block state and output commit points can create one-scan delays or races that a static truth table cannot reveal.
The controller or simulator captures the current input state for the scan.
Rungs and blocks execute in defined order using current and prior state.
Calculated outputs become visible at the bus or process boundary.
Physics changes and produces new feedback for a later input image.
A test must give each action enough scans to propagate through the controller and process model while still asserting maximum permitted response time.
Combinational logic may settle in one scan, while internal variables written late in the program are not consumed until a later scan depending on the execution model. A test that waits an arbitrary second will eventually see the right final value and hide an unintended delay. Express both the required deadline and the scan resolution: for example, output must drop no later than the next completed scan after Stop is observed.
Timers need temporal boundaries. Advance the simulated clock in known increments and assert before the preset, at the first eligible completion and after reset. Test what happens when the input drops just before completion, when the preset changes while active if supported, and when the preset is shorter than one scan. The goal is not to memorize one simulator implementation but to develop cases you can adapt to the target PLC.
Pulses need an on edge and an off edge separated by executable scans. Back-to-back software writes in the same observation cycle can collapse into a level that the program never reads. The simulator test runner explicitly schedules the falling edge and allows a low scan before another pulse, which is useful for counters and edge detectors. Real I/O may need input filters or high-speed hardware when pulse width approaches task timing.
Rung order deserves targeted tests where one internal value is written and read in the same scan. Reverse order can create a one-cycle delay even though each rung looks correct in isolation. Write a case that asserts the intermediate scan, not only the state a second later. Then document whether the delay is intended, harmless or a requirement violation.
Stateful control
A sequence test should prove not just that the machine reaches Done, but that it cannot skip, overlap or escape the required states under abnormal events.
Outputs safe; start requires valid mode, permissives and initial process state.
Each phase owns outputs, entry conditions, exit evidence and supervision time.
Abnormal input removes energy, records cause and blocks unsafe progression.
Cause clear plus authorized reset returns to a defined restart point.
The fault branch is part of the machine, not an afterthought. Every operating state needs a defined response to critical lost permissives and feedback timeouts.
List legal states and transitions before writing the test. For each state record entry conditions, commanded outputs, expected feedback, completion condition and timeout. Then write one case for the normal outgoing transition and at least one case proving that an invalid transition is rejected. If Discharge is only legal after MixComplete, try to request it from Idle and during Fill.
Test event timing at every transition. A limit switch may already be true on entry, become true during the phase or chatter near the boundary. Decide whether the transition needs an edge or a level. A stale true signal can make a new phase complete immediately unless the program proves that the actuator first left and then reached the target. The acceptance case should reflect the actual physical evidence required.
Inject faults in more than one state. Losing a guard during Idle may merely block Start; losing it during motion may require an immediate stop and a latched diagnostic. A level transmitter failure during Fill and during Discharge can demand different safe responses. Reusing one generic fault bit without state context can make the operator message too vague to recover safely.
Prove reset behavior from every faulted state that can occur. Reset should not silently advance to the next production phase, energize an actuator, or discard the cause before the operator can identify it. If recovery resumes a sequence rather than returning to Idle, that policy must be explicit and tested with the physical process in each possible position.
| Current state | Event | Required next state | Outputs and evidence |
|---|---|---|---|
| Idle | Valid Start | Fill | Inlet command on; mixer and discharge off |
| Fill | High level reached | Mix | Inlet off before mixer starts; level evidence retained |
| Mix | Guard opens | Fault | Motion command off; guard cause latched; no discharge |
| Fault | Reset while guard open | Fault | No restart; reset rejected or has no unsafe effect |
| Fault | Cause clear plus Reset | Defined recovery state | Outputs remain safe until a new valid transition |
Acceptance logic
Stopping at the first failure shortens feedback but hides the rest of the requirement surface. A multi-case runner can evaluate all independent requirements and issue one aggregate verdict.
Build the learner program and expose syntax or type errors before execution.
Reset runtime and physics, apply the case steps and emit a case result.
Recompile from fresh state and execute the next independent requirement.
Pass only when every required case passes; retain the failed case identities.
Each case gets a clean runtime and process state. A failed case contributes evidence but does not prevent later independent cases from being measured.
Independent requirements should produce independent outcomes. A program may pass Stop priority and fail overload recovery. Showing both results gives the learner a bounded repair task and tells an engineer which regression areas remain stable. The overall completion status should pass only when every required case passes, but the diagnostic view can still celebrate the requirements that are already correct.
Hidden checks can reduce answer-copying in an assessment, but they should not become arbitrary surprises. The public brief must state the behavioral requirement even if the exact input combination remains hidden. When a hidden check fails, reveal enough category guidance to support learning without exposing the entire answer. In engineering use, secrecy is usually less important than traceability; name the requirement directly.
Avoid source-shape grading unless structure is part of the requirement. Searching for a specific rung pattern rejects alternative correct implementations and can accept cosmetically similar but unsafe code. Execute the program across the full behavioral matrix. Structural rules still have a place for forbidden instructions, mandated safety architecture or maintainability conventions, but label them as separate static checks.
A failed assertion is not a controller fault. The program can remain syntactically valid and useful for iterative diagnosis. The simulator returns ordinary practice to a live scan after a grading mismatch, allowing the learner to inspect state and adjust the program. Production test tooling should make the same distinction between test failure, compile error, runtime fault and infrastructure failure.
Diagnosis loop
Useful evidence tells the programmer which case failed, what was applied, what was observed and what state should be inspected next.
Name the case and the promised behavior that was not met.
Show the ordered inputs, pulses, waits and process events up to failure.
Report tag, state or timing difference with units and tolerance.
Point to the likely permissive, transition, output path or timing boundary.
The purpose of a test runner is not merely judgment. It should shorten the path from mismatch to an evidence-backed correction.
Capture the failed step and a concise chronological log. “MOTOR_CONTACTOR = false, expected true after valid Start” is more useful than “Test failed.” The preceding log should show that Stop, emergency stop and overload were clear and that Start was pulsed for the intended duration. Without that context, the programmer cannot tell whether logic or test setup is wrong.
Include timestamps or elapsed simulated time around temporal requirements. A timer completing at 5.05 seconds may be correct with a 50 ms scan; completing at 8 seconds may not be. An analog assertion should include tolerance. A physics assertion should show the model state used, because a correct output can still fail to move a simulated actuator when another physical constraint blocks it.
Map common failures to next actions without revealing a canonical solution. If Start does not latch, inspect the branch that maintains the run state after the pulse. If Stop fails, check priority and active polarity. If a sequence times out, compare command, feedback and transition condition. The guidance should teach a diagnostic method rather than invite random edits.
Retain evidence in a format suitable for regression review. At minimum save scenario and case identifiers, program revision, dialect, date, result and failed assertion. A production FAT or regulated workflow may require signed records, controller versions, test equipment calibration and change control far beyond a browser exercise. Do not represent learning progress as formal commissioning evidence.
Honest boundaries
Different environments answer different questions. A disciplined plan keeps fast code tests, controller tests, I/O proving and process commissioning connected without pretending they are interchangeable.
Fast, repeatable checks of Boolean, numeric, sequence and timing intent.
Vendor compiler, task model, libraries, data layout and controller-specific behavior.
Real modules, signal ranges, networks, drives, sensors and wiring boundaries.
Controlled proof with the real machine, safeguards, people and process conditions.
Move expensive and hazardous discoveries left where possible, then repeat the critical acceptance cases as realism and risk increase.
Browser simulation is excellent for rapid logic feedback, training, regression cases and fault reasoning. It can run cases that would be slow or hazardous on equipment. Its physics model is deliberately bounded, its scan environment is not a real CPU under load, and its I/O values do not pass through actual modules, wiring or networks. Use it to improve the program and test design before scarce plant time.
Target-controller simulation or emulation adds the vendor compiler, libraries, memory behavior, task configuration and supported instructions. It can reveal differences in implicit conversions, timer resolution, retentive state and execution order. Networked or virtual-controller setups may also test HMI and supervisory interfaces. Confirm the exact limitations in the current vendor documentation.
Hardware-in-the-loop and point-to-point I/O testing prove the electrical and communication path. Operate field devices, compare terminal signal, module indication, raw tag and engineered value, and remove forces after each recorded check. A simulated limit switch does not prove polarity, addressing, noise immunity or mechanical actuation.
Commissioning proves the integrated system under an approved plan. Safeguards, risk assessment, reduced-energy tests, operators and emergency response matter. Repeat the highest-risk functional cases and all recovery paths. A browser pass is preparation and learning evidence; it is not a safety certification, FAT signature or authorization to energize machinery.
| Layer | Strong evidence for | Does not prove | Typical next gate |
|---|---|---|---|
| Browser logic simulation | Requirement logic, sequence cases, repeatable edge inputs | Vendor CPU, physical I/O, safety function | Run the same matrix in target tools |
| Target simulation / emulator | Compiler, libraries, task and vendor-specific execution | Field wiring and real process response | Integrate I/O or virtual plant |
| Hardware / I/O test | Addressing, signals, communications and actuator interfaces | Full production interaction by itself | Controlled sequence commissioning |
| Commissioning | Integrated response under approved real conditions | Every future operating condition | Monitor, maintain and regress changes |
Related technical cluster
These are the closest supporting owners and product surfaces. Each link advances a specific part of the same engineering task instead of sending you to a generic content index.
Verified product surface
The simulator already implements an executable, multi-case grading surface. The public guide describes that shipped behavior and the engineering method around it.
Scenario cases support set-input, timed wait, output assertion, physics-state assertion, input pulse and scenario event injection steps.
The engine resets physics and bus state, recompiles the submitted program between cases and aggregates every requirement result.
The runner records information, pass and failure entries with elapsed timestamps and reports the failed step rather than only a global red status.
The learner earns completion only after every required case passes; after a mismatch, the program can return to live scanning for diagnosis and iteration.
The browser test harness is educational and scenario-specific. It does not emulate every vendor task scheduler, safety runtime, physical I/O module, network failure or process hazard. Its pass record is not a FAT, SAT, regulated validation package or safety certification. Critical programs still require the target vendor toolchain, approved test plans and controlled hardware commissioning.
Answer-engine questions
Start from a written observable requirement, reset to a known state, apply a precise input sequence over scan time, assert outputs or process state, and record the verdict. Cover normal, boundary, fault, recovery and restart cases, then repeat critical cases on the target controller and real I/O.
A PLC test case is a reproducible sequence containing initial conditions, timed stimuli, expected observations and a pass/fail rule for one requirement. It should name the requirement and retain enough trace information to reproduce a failure after the program changes.
Test the behavior represented by the ladder: command priority, permissives, interlocks, latches, timers, counters, output transitions, faults and recovery. Avoid accepting a program solely because its rung resembles a preferred pattern when different safe structures can meet the same requirement.
Set a known scan interval, test before the preset, at the first eligible completion and after it, then remove the input and verify reset or retained behavior. Also test zero or short presets, interrupted timing and any supported live preset changes.
Model the legal states and transitions. Test every normal transition, reject invalid transitions, inject important faults in each operating state, verify output ownership and timeouts, and prove the defined reset and re-entry route without unintended restart.
Independent requirement tests should normally start from a clean documented state so timers, counters, latches and physics do not leak across cases. If prior state is part of the behavior, keep the dependent steps together in one scenario and describe that dependency.
Hidden cases can discourage copying in training, but they must test a requirement already stated in the brief. Engineering validation usually values transparent, traceable cases. A hidden failure should still return enough category guidance to help diagnose the control behavior.
No. Simulation can prove logic intent and repeat edge cases, but it cannot prove real wiring, module behavior, network timing, mechanical response, safeguarding or site procedures. Use it to find problems early, then repeat critical cases through target simulation, I/O tests and controlled commissioning.
Record the requirement and case identifiers, program revision and dialect, initial state, ordered stimuli, elapsed time, expected and actual values, final verdict and failed step. Formal industrial validation may also require controller versions, approvals, calibrated equipment and change control.
It supports multiple scenario cases with input writes, waits, pulses, output checks, physics-state checks and selected event injection. It resets and recompiles between cases, emits per-case progress and passes the aggregate only when all required cases pass.
Primary sources
This guide separates transferable engineering practice from product-specific behavior. Use the primary sources below for exact standard wording, target-controller support, firmware behavior and production design decisions.
Turn the guide into evidence
Choose a scenario, describe the required behavior in one sentence, then build a normal case, one boundary case and one fault-recovery case. Run them from fresh state until every result is reproducible.