Macros

Overview

Specific macros are available in the methods of ETEST objects. You can use these macros to control the test execution and determine the result of a test case.

Macros are called in the same way as methods. In contrast to a function call, a macro call can write variables of the calling method and can trigger a return of the calling method.

Macros are allowed in the following methods of test cases and resources:

  • Prepare

  • Execute

  • CleanUp

You can also use macros in methods that are called with ASSERT_SUBMETHOD.

NOTE: Using macros in other methods of test cases and resources can lead to errors. In particular, do not use macros in the method Finalize.

Macros in other objects do not have any effect. This is indicated by a message that is displayed in the Messages view.

Macros in the Methods of Test Cases and Resources

In the methods of test cases and resources, the following macros are possible:

Macro call-up

Description

ASSERT(condition)

FALSE: Execution is not completed successfully.

TRUE: Execution is completed successfully.

ASSERT(condition, message)

FALSE: Execution is not completed successfully.

TRUE: Execution is completed successfully.

message is the diagnostic message that is displayed as a result.

ASSERT_INCONCLUSIVE(condition, message)

FALSE: Test result is inconclusive.

The test result is inconclusive to indicate that a test could not be carried out. The cause may be, for example, that a hardware device required for the test is not available on the test system.

TRUE: Test is completed successfully.

ASSERT_SUBMETHOD(method_call(i_xFirstCall, i_ifErrorLogger))

With Method_call, methods can be called which in turn can use macros in order to influence the control flow of the calling method.

FALSE: An error has been detected during the method call-up.

An ASSERT in a method called by ASSERT_SUBMETHOD that has been evaluated to FALSE has the same effect as an ASSERT that has been evaluated to FALSE directly in the calling method.

In contrast to this, an ASSERT in a method called without using ASSERT_SUBMETHOD does not have any effect on the calling method.

When you use the ASSERT_SUBMETHOD, make sure to use the exact syntax concerning the parameter declaration and return type (also refer to example 2):

  • Declare i_ifErrorLogger in the submethod analog to the Execute method.

  • Declare and use the return type ET_TestReturn in the submethod analog to the Execute method.

  • The i_ifErrorLogger has to be transferred to the submethod as well.

TEST_DONE()

The execution of the test is completed successfully (without any errors detected). A simple RETURN only ends the current cycle. The method will then be called again in the next cycle.

Macros Stopping the Execution of Methods

The methods Prepare, Execute and CleanUp of a test case or a resource are called cyclically until an ASSERT is evaluated to FALSE or TEST_DONE is called. If a TEST_DONE is called or if an ASSERT is evaluated to FALSE, the execution of the method stops, cancelling the rest of the execution of the method.

If...

Then ...

the execution of a test is ended via TEST_DONE

the test has been successfully completed.

an assertion in the method Execute or Prepare is evaluated to FALSE

the test case did not complete successfully.

NOTE: If an assertion in the method CleanUp is evaluated to FALSE, the execution of the test is stopped. This is categorized as an error during initialization or de-initialization. A message is displayed in Logic Builder. It indicates that the test has been canceled and that a reset of the controller is required.

Example 1

In the following program code example, the macros ASSERT and TEST_DONE are used in the implementation part of the Execute method.

diResult := MyAdditionFunction(4, 3);
ASSERT(diResult = 7,  'MyAdditionFunction addition result not correct');
TEST_DONE();

Example 2

In the following program code example, the macros ASSERT and TEST_DONE are used to test the function my_add (a simple addition).

In the test case, a TestMyAdd method was created. It is called multiple times by the Execute method of the test case to test the function my_add under different boundary conditions and with different parameters.

(* Methode Execute *)
(* Declaration part*)
METHOD Execute : PD_ETest.ET_TestReturn
VAR_INPUT
   i_xFirstCall : Bool;
   i_ifErrorLogger : PD_ETest.IF_ErrorLogger;
END_VAR
VAR_OUTPUT
   q_rProgress : REAL;
   q_sState . STRING[255];
END_VAR
VAR
END_VAR
(* Implementation part*)
ASSERT_SUBMETHOD (TestMyAdd(12, 2, 14, i_ifErrorLogger));
ASSERT_SUBMETHOD (TestMyAdd(12, 3, 15, i_ifErrorLogger));
ASSERT_SUBMETHOD (TestMyAdd(12, 4, 16, i_ifErrorLogger));
TEST_DONE();
 
(* Submethod TestMyAdd *)
(* Declaration part *)
METHOD TestMyAdd : PD_ETest.ET_TestReturn
VAR_INPUT
   i_a : INT;
   i_b : INT;
   i_result : INT;
   i_ifErrorLogger : PD_ETest.IF_ErrorLogger;
END_VAR
VAR
   iResult : INT;
END_VAR
(* Implementation part *)
iResult : my_add(i_a, i_b);
ASSERT(iresult = i_result);
 
(* Function my_add *)
(* Declaration part *)
FUNCTION my_add : INT
VAR_INPUT
   a : INT;
   b : INT;
END_VAR
VAR
END_VAR
(* Implementation part *)
iResult : my_add := a + b;