Skip to main content

Scheme for Multitest POUs

Defining a test POU

If your test consists of multiple uniform test cases, then you can implement one multitest POU instead of many single test POUs. Multitest POUs follow a scheme similar to test POUs for single test cases and are flagged with the {attribute 'test' := 'multitest'} attribute. Other characteristics of the scheme can be found in the Interface convention. You can follow the scheme easily by using the wizard to create a test POU.

For more information, see the Examples.IecUnitTest example

Support during implementation

When you use the wizard to add a unit test, you will be provided with a sample implementation. The wizard will create a working example as long as you enable the Add implementation template option.

Basic test case function

Before the actual test execution (xGetTestInfo := FALSE), information is collected about the individual test cases of the POU. In this phase, the input xGetTestInfo has the value TRUE. With the value -1 at the diTestCaseIndex input, the number n of test cases is queried at the diTestCaseCount output. Then there is a sequence of queries that varies the values of the diTestCaseIndex input from 0 to n-1 in order to request the sTestCaseName, sTestCaseCategories, and diTestCaseTimeout information for each test case. Each query is performed by the Test Manager in a closed cycle from xExecute := TRUE, wait for xDone, or xError and reset of the xExecute input to FALSE.

Therefore, the test is executed as a sequence of closed cycles (xExecute to xDone or xError) that varies the diTestCaseIndex input from 0 to n-1. At that time, the xGetTestInfo input is always left at the value FALSE. A description can be output for the test report by means of the sInfo output. In case of error (xError := TRUE), the error code can be included in the test report by means of eError, and a description of the error situation by means of sError. If possible, the symbolic name of the error code is included in the log.

A test block which has been created with the wizard encapsulates this behavior in the scheme of the base POU TM.BaseMultiTest (defined in the IEC Unit Test library). For the execution of the test logic, the prvCyclicAction method is available as a frame in which the testee should be stimulated. Furthermore, easy-to-use Assert Functions are provided for checking the result and reporting errors.

For more information, see: Implementing a single test POU

Timeouts in test POUs

You use timeouts to define maximum time spans for executing the test. If the value is exceeded, then the system aborts with an error. The remaining test cases are skipped. You define the timeouts in the wizard in the Add Unit Testdialog.

Test Case Name

With the optional entry of a test case name, you can give the test case, which has been implemented in the test POU, an alternative name (default: POU name of the test POU). You can use this name in the IEC Unit Test test element to select/except the test case like the POU name. The test case name is displayed in the test report, if applicable.

For more information, see: Pragmas in Test POUs

Test Case Category

Test cases can be organized into categories with which they can be selected/excluded collectively in the IEC Unit Test element. A test case can belong to multiple categories.

For more information, see: Pragmas in Test POUs

Interface convention

The interface convention is automatically followed by a test POU, which has been created with the wizard and maintains the scheme of TM.BaseMultiTest, and is automatically evaluated by the IEC Unit Test test element. The interface convention is therefore interesting when a test POU has to be triggered manually, for example for debugging. In addition, the Pragmas in Test POUs apply.

Name

Type

Scope

Optional

Description

xExecute

BOOL

VAR_INPUT

Starts and checks the execution of the POU

xAbort

BOOL

VAR_INPUT

Aborts the test according to the CAA Behaviour Model

xGetTestInfo

BOOL

VAR_INPUT

TRUE: The information is retrieved with the test case specified in diTestCaseIndex and sent to the corresponding outputs.

FALSE: The test case defined in diTestCaseIndex is executed.

They may take several cycles also for actions with xGetTestInfo set. Also for these actions, xExecute is set and xDone is waited for according to the CAA Behaviour Model.

diTestCaseCount

Integer data type

VAR_OUTPUT

X

Number of test cases provided by this test POU

If the directive testcasecount is not set, then diTestCaseIndex=-1 and xGetTestInfo are used for getting it.

diTestCaseIndex

Integer data type

VAR_INPUT

Test case which is processed

[w]sTestCaseName

STRING / WSTRING

VAR_OUTPUT

X

Test case name which can be read by means of xGetTestInfo

If the name was specified by a direct line and is not an empty string, then it is included in the test report.

[w]sTestCaseCategories

STRING / WSTRING

VAR_OUTPUT

X

Additional test categories assigned to the specified individual test case

diTestCaseTimeout

Integer data type

VAR_OUTPUT

X

Timeout of the test case (in milliseconds)

If the value is greater than 0, then it is the timeout for this test case (and overwrites any test cases for each directive). Negative values are reserved for future use and lead to abort.

xBusy

BOOL

VAR_OUTPUT

TRUE: The test case is running.

xDone

BOOL

VAR_OUTPUT

TRUE: The test case was completed.

xError

BOOL

BOOL

VAR_OUTPUT

VAR_OUTPUT

TRUE: The test case was aborted with errors.

xAborted

BOOL

VAR_OUTPUT

TRUE: The test case was aborted by an xAbort.

[w]sInfo

STRING / WSTRING

VAR_OUTPUT

X

Additional text information for test report

eError

Enumeration

VAR_OUTPUT

X

Enumeration value of the error description

Requirement: An error has occurred.

[w]sError

STRING / WSTRING

VAR_OUTPUT

X

More detailed textual error description

Implemented also for function blocks which are not multitest-capable

Requirement: An error has occurred.

[w]sWarning

STRING / WSTRING

VAR_OUTPUT

X

Warning message for the test report

Implemented also for function blocks which are not multitest-capable

eFailureMode

TM.FailureMode

VAR_OUTPUT

X

Failure mode (error handling) of the test case

Implemented also for function blocks which are not multitest-capable