C/AL ASSERTERROR Statements
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 causes 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 cause an error, then the ASSERTERROR statement causes the following error and the test function that is running produces a FAILURE result:
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 := 010184D; InvalidDateErrorMessage := Text001; ASSERTERROR CheckDate(InvalidDate); IF GETLASTERRORTEXT <> InvalidDateErrorMessage THEN ERROR('Unexpected error: %1', GETLASTERRORTEXT);
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.