Skip to main content

Assert Functions

Using the assert functions (asserts), you can easily check whether or not the response of the DUT corresponds to the expected response. This allows you to have the unit test implicitly respond to the test result.

Every assert function returns a result of the check as BOOL, where TRUE means a successful check and FALSE means a failed check. Optionally, you could define an error text which is output as a message in case of an error.

To check several different conditions one after the other, typically one assert call per condition is used as a single statement. If the condition of an assert call does not apply, then the error outputs of the test POU are automatically written accordingly and the following assert calls are no longer executed.

Sometimes it can also be useful to use compound conditions in asserts, for example when the control flow of the test logic has to depend on several conditions. The only correct way to create a compound condition with asserts is to use the AND_THEN statement.

IF (Assert_Bool_IsTrue(^THIS, value1, "") AND_THEN
    Assert_Bool_IsFalse(^THIS, value2, "")) THEN
        // do something
END_IF

Important

If you use a test POU of type ETrigA and want to use assert functions, then you need to implement the missing interfaces HandleAssertResult and HasError in the test POU. This is done by means of the Implementing Interfaces command in the context menu. Furthermore, check the test POU directly to change the TM.Testcase scheme.

For more information, see: Obsolete Test POU Implementations

Asserts for Bool

Name

Description

Assert_Bool_Equal(THIS^, <actual>, <reference>, "")

Successful when the actual value matches the reference value.

Assert_Bool_NotEqual(THIS^, <actual>, <reference>, "")

Successful when the actual value does not match the reference value.

Assert_Bool_IsTrue(THIS^, <actual>, "")

Successful when the actual value is TRUE.

Assert_Bool_IsFalse(THIS^, <actual>, "")

Successful when the actual value is FALSE.

Asserts for numeric data types

Name (*)

Description

Assert_TYPE_Equal(THIS^, <actual>, <reference>, "")

Successful when the actual value matches the reference value.

Assert_TYPE_NotEqual(THIS^, <actual>, <reference>, "")

Successful when the actual value does not match the reference value.

Assert_TYPE_Greater(THIS^, <actual>, <reference>, "")

Successful when the actual value is greater than the reference value.

Assert_TYPE_GreaterEqual(THIS^, <actual>, <reference>, "")

Successful when the actual value is greater than or equal to the reference value.

Assert_TYPE_Less(THIS^, <actual>, <reference>, "")

Successful when the actual value is less than the reference value.

Assert_TYPE_LessEqual(THIS^, <actual>, <reference>, "")

Successful when the actual value is less than or equal to the reference value.

(*) For the name, the TYPE placeholder has to be replaced with the default IEC data type from the table below

Table 1. Values for TYPE

TYPE

IEC data type

TYPE

IEC data type

Date

DATE

DInt

DINT

DateAndTime

DATE_AND_TIME

DWord

DWORD

LDate

LDATE

Int

INT

LDateAndTime

LDATE_AND_TIME

LInt

LINT

LTimeOfDay

LTIME_OF_DAY

LWord

LWORD

Time

TIME

SInt

SINT

LTime

LTIME

UDInt

UDINT

TimeOfDay

TIME_OF_DAY

UInt

UINT

LReal

LREAL

ULInt

ULINT

Real

REAL

USInt

USINT

Byte

BYTE

Word

WORD



Asserts for String

Name

Description

Assert_String_Equal(THIS^, <actual>, <reference>, "")

Successful when the actual string matches the reference string.

Assert_String_NotEqual(THIS^, <actual>, <reference>, "")

Successful when the actual string does not match the reference string.

Assert_String_Contains(THIS^, <actual>, <reference>, "")

Successful when the actual string contains the reference string.

Assert_String_ContainsNot(THIS^, <actual>, <reference>, "")

Successful when the actual string does not contain the reference string.

Assert_String_StartsWith(THIS^, <actual>, <reference>, "")

Successful when the actual string starts with the reference string.

Assert_String_EndsWith(THIS^, <actual>, <reference>, "")

Successful when the actual string ends with the reference string.

Asserts for WString

Name

Description

Assert_WString_Equal(THIS^, <actual>, <reference>, "")

Successful when the actual value matches the reference value.

Assert_WString_NotEqual(THIS^, <actual>, <reference>, "")

Successful when the actual value does not match the reference value.

Assert_WString_Contains(THIS^, <actual>, <reference>, "")

Successful when the actual WString contains the reference WString.

Assert_WString_ContainsNot(THIS^, <actual>, <reference>, "")

Successful when the actual WString does not contain the reference WString.

Asserts for Array

The set of provided assert functions is limited for specific data types:

  • Date and time types: No array assert functions available

  • BOOL: Full set of array assert functions except ContainsOneOf, ContainsAllOf, and ContainsNoneOf.

  • String, integer, floating point types: Full set of array assert functions (as follows).

Example: Full set of assert functions for STRING arrays

Name

Description

Assert_ArrayOfString_Equals(THIS^, <actual>, <reference>, "")

Successful when all of the following conditions are fulfilled:

  • Every element of the ARRAY [n..m] OF STRING reference is found in the ARRAY [i..j] OF STRING actual.

  • Every element has the same array index in both arrays.

  • The lower and upper limits of both arrays are the same.

Assert_ArrayOfString_NotEquals(THIS^, <actual>, <reference>, "")

Successful when at least one of the following conditions is not fulfilled:

  • Every element of the ARRAY [n..m] OF STRING reference is found in the ARRAY [i..j] OF STRING actual.

  • Every element has the same array index in both arrays.

  • The lower and upper limits of both arrays are the same.

Assert_ArrayOfString_Contains(THIS^, <actual>, <reference>, "")

Successful when the STRING reference is found at least one time in the ARRAY [i..j] OF STRING actual.

Assert_ArrayOfString_ContainsNot(THIS^, <actual>, <reference>, "")

Successful when the STRING reference is not found in the ARRAY [i..j] OF STRING actual.

Assert_ArrayOfString_ContainsOneOf(THIS^, <actual>, <reference>, "")

Successful when at least one element of the ARRAY [n..m] OF STRING reference is found in the ARRAY [i..j] OF STRING actual.

Assert_ArrayOfString_ContainsNoneOf(THIS^, <actual>, <reference>, "")

Successful when no element of the ARRAY [n..m] OF STRING reference is found in the ARRAY [i..j] OF STRING actual.

Assert_ArrayOfString_ContainsAllOf(THIS^, <actual>, <reference>, "")

Successful when all elements of the ARRAY [n..m] OF STRING reference are found in the ARRAY [i..j] OF STRING actual (regardless of bounds or index).

Assert_ArrayOfString_ContainsSequence(THIS^, <actual>, <reference>, "")

Successful when all of the following conditions are fulfilled:

  • Every element of the ARRAY [n..m] OF STRING reference is found in the ARRAY [i..j] OF STRING actual.

  • The order of the elements is the same in both arrays