Frequently asked questions

Here you’ll find the most commonly asked questions and their answers. If you don’t find what you are looking for here, you can look through the open and closed issues on GitHub.


This can be accomplished by keeping the function block under test as an instance variable of the test suite rather than the test method. You can download an example here. In this example, the FB_ToBeTested is instantiated under the test suite (FB_ToBeTested_Test), and can thus be controlled over multiple cycles. Then all that’s necessary to do is to set the condition for when the assertion should be made in the test itself, which in the example is when the TestSuiteTimer has elapsed (TestSuiteTimer.Q).



Add DISABLED_ in front of the test name, for example:


AssertEquals(Expected := a,
             Actual := b,
             Message := 'A does not equal B');




In a number of scenarios, TwinCAT won’t let you write directly to certain variables:

  • Due to access restrictions (e.g. a variable in a FB’s VAR)
  • The variable being set as I/O (i.e. AT %I* or AT %Q*)

Writing to these variables wouldn’t make sense and should be prevented in the normal PLC code, so having special privileges during testing is a must.
To support these cases, TcUnit provides helper functions like WRITE_PROTECTED_BOOL, WRITE_PROTECTED_INT (and so forth) for setting these type of variables. For an example of how to use these, let’s assume you have a test:

METHOD PRIVATE TestCommsOkChannelsLow
    EL1008 : FB_Beckhoff_EL1008;

Where the FB_Beckhoff_EL1008 holds a variable:

iChannelInput AT %I* : ARRAY[1..8] OF BOOL;

Now you might want to write a value to the first channel of the iChannelInput like:

TcUnit.WRITE_PROTECTED_BOOL(Ptr := ADR(EL1008.iChannelInput[1]),
                            Value := FALSE);

Whereas afterwards you can make an assertion as usual:

AssertFalse(Condition := EL1008.ChannelInput[1],
            Message := 'Channel is not false');



You can accomplish this by the Hide reference option for referenced libraries. This option lets you hide TcUnit from your other projects.
Let’s assume you’ve developed a library MyLibrary, which has tests written in TcUnit. You make a PLC project MyProject, which references MyLibrary.

If you use Hide reference on TcUnit in MyLibrary, then TcUnit won’t show up in the imports list of MyProject. You can find it in the Properties tab: