How do I test functions?

It’s done almost identical as in the introduction user guide, but simply replace the instance of the function block that you want to test with the call to the function instead.
Assume we have a function:

FUNCTION F_Sum
VAR_INPUT
    one : UINT;
    two : UINT;
END_VAR

F_Sum := one + two;

Then the test would look like following:

METHOD TwoPlusTwoEqualsFour
VAR
    Result : UINT;
    ExpectedSum : UINT := 4;
END_VAR

TEST('TwoPlusTwoEqualsFour');

Result := F_Sum(one := 2, two := 2);

AssertEquals(Expected := ExpectedSum,
             Actual := Result,
             Message := 'The calculation is not correct');

TEST_FINISHED();
Category: TcUnit
  • Share on:

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.