Skip to content

Your first SCL unit test: a five-step tutorial

AnyAutomationUpdated 1 min read

An SCL unit test (overview: TIA Portal unit tests) checks a single TIA block in isolation: set defined inputs, let the controller run a few cycles and check the outputs against expected values. This guide walks the flow in five steps (against PLCSIM Advanced, without physical hardware).

Prerequisites

You need PLCSIM Advanced V3.0+ installed and a TIA project with at least one PLC. In AnyAutomation Studio you open the unit-testing workspace via the beaker icon in the activity bar.

1. Create a test suite

Click New Test Suite, pick the PLC and the block under test. Studio reads the block interface straight from the TIA project and pre-fills the suite with the real parameter names. The suite lands as .tia-tests/<name>.json next to your project file.

2. Arrange: set inputs

In the arrange step you write the start values: StartCmd: true, Reset: false, Speed: 50.0. These go into the block's instance DB before the run.

3. Act: run cycles

Set act.cycles to a sensible value (3-10 is typical). The PLC runs the given cycles before measuring. For timed sequences, use act.steps with write/wait/assert instead.

4. Assert: check outputs

Assertions compare outputs to expectations: Run is equal true, Speed_Act is inRange [49.5, 50.5]. Over 20 operators are available, from equal to approximately for fuzzy Real comparisons.

5. Run and evaluate

Start Run Test Suite. The runner creates the PLCSIM instance, compiles, connects, writes the inputs and evaluates the assertions. The Test Results view shows pass/fail per assertion; every run is stored in the history.

Where next

Let the AI author your test suite, run suites in the CI/CD pipeline or read the full reference in the unit testing documentation. More on the topic: SCL unit testing for TIA Portal.

Try it now

Try AnyAutomation Studio free for 30 days

Try the workflows from these articles in your own TIA Portal or CODESYS project.

Free account required: sign in with your email address and a code, then the download starts.

Questions? support@anyautomation.ch