Thursday, October 1, 2009


You use ASSERTERROR statements in test functions to test how your application behaves under failing conditions. The ASSERTERROR keyword specifies that an error is expected at run time in the statement that follows the ASSERTERROR keyword.

If a simple or compound statement that follows the ASSERTERROR keyword results in an error, then execution successfully continues to the next statement in the test function. You can get the error text of the statement by using the GETLASTERRORTEXT Function.

If a statement that follows the ASSERTERROR keyword does not result in an error, then the ASSERTERROR statement itself fails with the following error and the test function that is running produces a FAILURE result:

TestAsserterrorFail: FAILURE

An error was expected inside an ASSERTERROR statement.


To create a test function to test the result of a failure of a CheckDate function that you have defined, you can use the following code. This example requires that you create a function called CheckDate to check whether the date is valid for the customized application and that you create the following text constant and variables.

Text constant
ENU value

Text001 'The date is outside the valid date range.'


InvalidDate Date

InvalidDateErrorMessage Text

InvalidDate := 010184D;
InvalidDateErrorMessage := Text001;
ASSERTERROR CheckDate(InvalidDate);
ERROR('Unexpected error: %1', GETLASTERRORTEXT);

Also check the output without ASSERTERROR function.

No comments:

Post a Comment