In the third blog post in the Unit Tests series, our developers Max and Basti, use a sample tutorial to demonstrate the implementation of unit tests. They use the Eclipse development environment and follow the test-driven development approach.
The first step to implement unit tests in ABAP is to create a global class. The logic will be implemented later. Subsequently, a test class is created for this class. There, the individual unit tests must be implemented in the form of methods in order to test the logic. In this tutorial, we use Eclipse because it simplifies matters and offers good features in creating unit tests. Furthermore, we are writing test-driven in this tutorial and this means that we are writing the test before the logic.
This is best explained by a sample task :
The task is as follows: Create a class with a method that checks what type of availability check is made when the following input parameter meets a predefined value (in the “real” case. There are certainly more input parameters but for this tutorial we’re trimming it to something smaller in order to get a basic understanding of unit tests):
Possible input values are:
Possible return parameters:
o N: No test/check
o V: full test/check
o S: quick test/check
Unless otherwise determined by the method, a quick check should always be performed. In case something else is determined, the following rules apply:
- MTART PROD = Full Test/check (V)
• MTART HALB = Full Test/check (V)
• MTART FERT = No Test/check (N)
# Implementation ## 1. Creating a Global Class in Eclipse! [Create New Class] (./ assets / gif / new-class.gif)
This class remains empty for now. We will implement the logic at a later stage.
Creation of the test class