Unit Testing - Part 1

Functionality

The class CL_AUNIT_ASSERT contains the following static methods for the verification of test expectations withinABAP Unit test methods:
  • ASSERT_EQUALS: Ensures the equality of two data objects
  • ASSERT_EQUALS_F: Ensures the equality of two floats with a rel. tolerance.
  • ASSERT_DIFFERS:Ensures the inequality of two elementary data objects.
  • ASSERT_BOUND: Ensures whether the reference of a reference variable is valid
  • ASSERT_NOT_BOUND: Ensures whether the reference of a reference variable is invalid
  • ASSERT_INITIAL: nsures that a data object has its initial value
  • ASSERT_NOT_INITIAL: Ensures that a data object does not have its initial value
  • ASSERT_SUBRC: Requests specific value of sy-subrc
  • FAIL: Terminates the test with an error
  • ABORT: Cancels the test due to a missing context (ideally in setup method)

All the methods have the optional importing parameters MSG, LEVEL, and QUIT, which always have the same meaning:
  • MSG (Type: CSEQUENCE): Contains a more detailed description of the error (if applicable)
  • LEVEL (Type: AUNIT_LEVEL): ndicates the severity of the error; the following values are possible:
  • TOLERABLE - Minor error (may be tolerable)
  • CRITICAL - Critical error (default value)
  • FATAL - Fatal error

  • QUIT (Type: AUNIT_FLOWCTRL):Determines the flow control in the case of an error. The following values can be passed:
NO - No termination in the case of an error; processing of the current method continues after the relevant method is called
METHOD - The currently processed test method is terminated (default value)
CLASS - The currently processed test class is terminated
PROGRAM - The test of the currently processed main program is terminated: The current test class is terminated and all other test classes in the program are ignored.


All the assert methods have the following mandatory importing parameter:
ACT (Type: Any)
The object to be verified
The comparing method ASSERT_EQUALS additionally requires a parameter for the expectation:
EXP (Type: Any)
The identically expected object
TOL (Type: f)
Allows you to compare floating point numbers for the passed tolerance

1 comment:

  1. http://help.sap.com/abapdocu_70/en/ABENNEWS-710-TOOLS.htm#!ABAP_MODIFICATION_7@7@

    ReplyDelete