SAP ABAP Unit Testing Class

by | May 28, 2019 | OOABAP

Home » SAP » ABAP » OOABAP » SAP ABAP Unit Testing Class

Preface – This post is part of the Object Oriented ABAP series.


ABAP unit testing is a methodology for software development. Whenever we create a class, it is mandatory to create its test class to check the behavior of our code if it is working exactly as it was expected.  While developing any object, it helps the developer to cover all possible scenarios. With ABAP unit test class, we can also check the coverage of code lines.


ABAP unit test class provides a methodology to test the individual source of code to determine if they are fit to use.

The global class CL_UNIT_ASSERT contains a method that can be used for testing, the following are the most common methods:

  1. ASSERT_EQUALS – Checks the equality of two data objects.
  2. ASSERT_DIFFERS – Checks for the difference between two data objects.
  3. ASSERT_BOUND – Checks for the validity of the reference of a reference variable.
  4. ASSERT_INITIAL – Checks whether the reference of a reference variable is invalid.
  5. ASSERT_NOT_INITIAL – Checks whether the data object is not having its initial value.
  6. ASSERT_SUBRC – Checks for the specific value of SY-SUBRC.


Below is a method ‘GET_ORDER_DATA’ of class ‘ZCL_PROD_ORD_TEST ‘  to fetch the operation details from the production order.

Note: Local Test Class will get generated automatically through test class generation wizard.

Method get_order_data

Figure 1: Method get_order_data

OSQL test double Framework : To remove the dependency from database tables.

Unit Test Class

Figure 2 : Unit Test Class

Mocking virtual database tables to test the behavior of code.

Unit Testing of Method GET_ORDER_DATA

Figure 3: Unit Testing of Method GET_ORDER_DATA


  1. ABAP Unit provides excellent support for test-driven development in ABAP.
  2. You can run tests quickly and easily right from the development environment.
  3. You can navigate back and forth between a test class and the production code.
  4. With ABAP Unit test class, there is no such dependency on availability on test data to test the functionality.
  5. Fewer bugs reported with ABAP unit testing and less time wasted.


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.