Yes. By default TcUnit runs all the test suites and tests in parallel, in other words all test suites and tests are run at the same time. Sometimes it is however desirable to run either the test suites or tests (or both) in a sequence, for example if you get exceed overruns while running tests. Since TcUnit 1.2 it’s possible to run test suites in sequence (one after another) and/or individual tests in order (one after another).
To execute test suites in a sequence, simply replace TcUnit.RUN()
with TcUnit.RUN_IN_SEQUENCE()
in your main body of the test program. This will execute the test suites in the order that they were declared. So for example if we have defined the following test suites and test program:
PROGRAM PRG_TEST
VAR
fbDiagnosticMessageDiagnosticCodeParser_Test : FB_DiagnosticMessageDiagnosticCodeParser_Test;
fbDiagnosticMessageFlagsParser_Test : FB_DiagnosticMessageFlagsParser_Test;
fbDiagnosticMessageParser_Test : FB_DiagnosticMessageParser_Test;
END_VAR
TcUnit.RUN_IN_SEQUENCE();
This will first execute all tests defined in fbDiagnosticMessageDiagnosticCodeParser_Test
, once all tests are finished in that function block, TcUnit will execute all tests in fbDiagnosticMessageFlagsParser_Test
, and when that is done it will execute all tests in fbDiagnosticMessageParser_Test
.
It’s also possible to execute individual tests in order by simply replacing TEST('TestName')
with TEST_ORDERED('TestName')
. This will execute the tests in the order that the TEST_ORDERED()
is called for the various tests. TEST_ORDERED()
returns a boolean to indicate whether the TcUnit framework will run the test, so in order to only execute the code when it’s time for that particular test, it makes sense to check if TEST_ORDERED()
returns true, and only then do the execution of the function blocks and assertions, for example like this:
METHOD PRIVATE TestWithTimestampZeroTimeExpectCurrentTime
VAR
... (variable declaration used for the test)
END_VAR
IF TEST_ORDERED('TestWithTimestampZeroTimeExpectCurrentTime') THEN
fbFunctionBlockUnderTest(Parameters);
AssertEquals(Expected := 'SomeValue',
Actual := fbFunctionBlockUnderTest.OutVariable,
Message := 'Test failed');
TEST_FINISHED();
END_IF
As usual, the TEST_FINISHED()
will indicate that this test is finished, and the framework will go to the next test. Note that you don’t need to create any state machine for calling the different TEST_ORDERED()
tests. You can (and must!) call all TEST_ORDERED()
at the same time. The framework will make sure to only care about the assertions of the test that is currently running.
This means the following combinations can be used:
RUN()
with all tests as TEST()
– means all tests suites and tests will run in parallel, this is the default behaviour in all previous versions of TcUnit

RUN_IN_SEQUENCE()
with all tests as TEST()
– means all test suites will run in sequence, but the tests in every test suite will run in parallel

RUN()
with all tests as TEST_ORDERED()
– means all test suites will run in parallel, but the tests in every test suite will run in sequence

RUN_IN_SEQUENCE()
with all tests as TEST_ORDERED()
– means all test suites will run in sequence, as will every test

For maximum flexibility, these combinations are allowed as well for special occasions:
TcUnit.RUN()
with mixed tests of TEST()
and TEST_ORDERED()
– means all tests suites will run in parallel, with tests marked as TEST()
run in parallel with tests that are marked with TEST_ORDERED()
that run in sequence (relative to each other)
TcUnit.RUN_IN_SEQUENCE()
with mixed tests of TEST()
and TEST_ORDERED()
– means all test suites will run in sequence, with tests marked as TEST()
run in parallel with tests that are marked with TEST_ORDERED()
that run in sequence (relative to each other)
If you run tests with both TEST()
and TEST_ORDERED()
, all tests defined with TEST()
will run in parallel with the tests that are TEST_ORDERED()
.
Note that you can’t execute test-suites with both TcUnit.RUN()
and TcUnit.RUN_IN_SEQUENCE()
at the same time (which wouldn’t make any sense).
For a couple of TwinCAT projects that shows how to run both test suites in a sequence and individual tests in order, click here.
Required TcUnit version: 1.2 or later