Show TOC

Methods of Class CL_ABAP_UNIT_ASSERTLocate this document in the navigation structure

Definition

Start ABAP Unit Tests in Test Methods of procedures to be tested and then check if an expected effected has taken place. Using the methods of class CL_ABAP_UNIT_ASSERT, the test method can ensure that the expectations are fulfilled.

If a test does not meet the test expectations, the errors are logged and displayed in the Test Evaluation. Optional input parameters for the methods control the individual behavior.

Use

Class CL_ABAP_UNIT_ASSERT contains the following methods for checking test expectations:

  • ASSERT_EQUALS

    Checks the deflection if two objects are the same. The objects must have a comparable type. A deeper comparison is executed, that is, tables and structures (even nested ones) are checked for the content of their components.

    Standard method in test classes generated with the ABAP Unit Wizard.

    The method can be enhanced to make complex Checks of ABAP Object Instances vorzunehmen.

  • ASSERT_DIFFERS

    Ensures the differences between two elementary data objects (type SIMPLE). A check error is triggered if the types of the data object cannot be converted into each other.

  • ASSERT_BOUND

    Checks the validity of the reference of a reference variable by testing the ABAP property IS BOUND.

  • ASSERT_NOT_BOUND

    Checks the non-validity of the reference of a reference variable by testing the ABAP property IS NOT BOUND.

  • ASSERT_INITIAL

    Checks an object for its initial value by testing the ABAP property IS INITIAL.

  • ASSERT_NOT_INITIAL

    Ensures that a data object does NOT have its initial value (check the ABAP property IS NOT INITIAL).

  • ASSERT_CHAR_CP

    Ensures that a character string matches a simple pattern. Possible wildcards are asterisk (*) and question mark (?). Check regular expressions using the method ASSERT_TEXT_MATCHES.

  • ASSERT_CHAR_NP

    Ensures that a character string does not match a simple pattern. Possible wildcards are asterisk (*) and question mark (?). Check regular expressions using the method ASSERT_TEXT_MATCHES.

  • ASSERT_TEXT_MATCHES

    Ensures that a character string fulfills the conditions of a regular expression.

  • ASSERT_TABLE_CONTAINS

    Ensures that a data object appears as a row in an internal table.

  • ASSERT_NUMBER_BETWEEN

    Ensures that a numerical value lies within a specific value range.

  • ASSERT_SUBRC

    Requires a specific value of the return value sy-subrc.

  • ASSERT_EQUALS_FLOAT

    Ensures approximate equality of two floating point numbers. Valid data types are DECFLOAT and F.

  • ASSERT_THAT

    Ensures that a data object fulfills the specified Conditions. For more information, see here.

  • FAIL

    Terminates a test with an error.

  • ABORT

    Terminates a test because test prerequisites are not specified.

Method Parameters

All methods have the optional import parameters MSG, LEVEL, and QUIT with the same meaning:

  • MSG (type: CSEQUENCE) contains (if available) a text that describes the error in more detail

  • LEVEL (type: AUNIT_LEVEL) describes the severity of the error and can have the following values:

    • TOLERABLE- simple (tolerable) error

    • CRITICAL- (default) critical error

    • FATAL- fatal error

  • QUIT (type: AUNIT_FLOWCTRL) influences the flow control in case of an error.

    The following values can be transferred:

    • NO- No termination in case of an error. The current method is continued after calling the affected methods.

    • METHOD- (default) the test method currently being processed is terminated.

    • CLASS- the test class currently being processed is terminated.

    • PROGRAM- the test of the framework program currently being processed is terminated: The current test class is terminated and all other test classes of the program are ignored.

All assert methods have the non-optional import parameter

  • ACT (type: Any) - object to be verified

The comparing method ASSERT_EQUALS also needs a parameter for the expectation:

  • EXP (type: Any) - a data object with the expected values and properties.

The comparing method ASSERT_EQUALS_FLOAT also offers the parameter

  • RTOL (type: f) - permits the comparison of floating point numbers on transferred tolerance.