Write an ABAP Unit Test for the RAP Business Object
- How to create ABAP unit test class
- How to enhance test class definition
- How to implement special methods
- How to implement test method
- How to run your ABAP unit test
Prerequisites
- You need to have access to an SAP BTP, ABAP environment, or SAP S/4HANA Cloud, ABAP environment or SAP S/4HANA (release 2021 or higher) system.
For example, you can create free trial user on SAP BTP, ABAP environment. - You have downloaded and installed the latest ABAP Development Tools (ADT) on the latest Eclipse© platform.
In the previous exercise, you’ve implemented the dynamic instance feature control for some of the standard and non-standard operations of the Travel entity.
In the present exercise, you will write scenario tests for your business object to verify its transactional behavior as a whole. You will write an ABAP Unit test with the Entity Manipulation Language (EML). The scenario to be tested in the present exercise is the creation and manipulation of a new travel instance.
Reminder: Do not forget to replace the suffix placeholder ### with your chosen or assigned group ID in the exercise steps below.
About: ABAP Unit Testing
Ensuring the high quality of applications has a very high priority in the whole software development lifecycle. As an application developer, you want to be able to write, for example, unit, scenario and integration tests to verify the application behavior as a whole. The ABAP platform offers different mechanisms and frameworks to achieve this. The main options here are ABAP Unit Tests and the ABAP Test Cockpit.
Writing ABAP Unit tests is the way to provide high quality software, which can be easily evolved over time without introducing regressions. In methodologies, like extreme programming and test driven development, the role of unit testing is even more important.
ABAP Unit is the state-of-the-art unit testing framework for ABAP. It’s embedded into the ABAP programming language which supports you in writing unit tests. In ADT you have various possibilities to execute the unit tests and to evaluate the results concerning functional correctness and code coverage.
Further reading : Test@RAP Development Guide | Testing the RAP Business Object | Ensuring Quality of ABAP Code
About: Simplified Runtime flow of ABAP Unit Test Classes
The ABAP Unit framework has standard special methods which needs to be implemented to set up and destroy a given test configuration.
The standard special static methods of the test configuration
class_setup()
andclass_teardown()
,class_setup()
: This setup method is executed once before all tests of the class. It is used to setup the test environment.
class_teardown()
: Thisteardown
method is executed once after all tests of the test class are executed. It is used to destroy the test environment.The standard special instance methods of the test configuration:
setup()
andteardown()
.setup()
: This method is executed before each individual test or before each execution of a test method. It is used, for example, to reset the test doubles before the execution of each test method.
teardown()
: This method is executed after each individual test or after each execution of a test method. It will be used to rollback any changes in involved entities
Below is a simplified representation of the runtime flow of ABAP Unit test classes.ABAP Unit test methods:
() represents each unit test method for a given code under test (CUT). Such method is identifiable by the addition FOR TESTING in the method interface.