Preface – This post is part of the Object Oriented ABAP series.
Table of Contents
Introduction
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.
Definition
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:
- ASSERT_EQUALS – Checks the equality of two data objects.
- ASSERT_DIFFERS – Checks for the difference between two data objects.
- ASSERT_BOUND – Checks for the validity of the reference of a reference variable.
- ASSERT_INITIAL – Checks whether the reference of a reference variable is invalid.
- ASSERT_NOT_INITIAL – Checks whether the data object is not having its initial value.
- ASSERT_SUBRC – Checks for the specific value of SY-SUBRC.
Program
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.
Figure 1: Method get_order_data
OSQL test double Framework : To remove the dependency from database tables.
Figure 2 : Unit Test Class
Mocking virtual database tables to test the behavior of code.
Figure 3: Unit Testing of Method GET_ORDER_DATA
Advantages
- ABAP Unit provides excellent support for test-driven development in ABAP.
- You can run tests quickly and easily right from the development environment.
- You can navigate back and forth between a test class and the production code.
- With ABAP Unit test class, there is no such dependency on availability on test data to test the functionality.
- Fewer bugs reported with ABAP unit testing and less time wasted.
0 Comments