ABAP Unit Test Class generation wizard comes in handy when you got to design the test class for the Global Class. Lets see how easy it is to use the wizard.
I have started the series long back but couldn’t finish it earlier as there isn’t much love for ABAP unit (yet) in the community. I think it would gain the traction in the future for sure. Till the time, I would keep on going the planned articles on the ABAP Unit. In the series:
- ABAP Unit Test Driven Development Basic Example
- ABAP Unit Test Driven Development Basics
- ABAP Unit Test Fixture methods
- ABAP Unit Test Global class usage
- ABAP Unit Test Wizard to generate Test class – This article
- ABAP Unit Test Real time example
- ABAP Unit Test Advantages
Prerequisite to using the Wizard
You need to take few steps before you should start the test class wizard, so you don’t face any errors
- Create Local Test Classes include (ABAP 731) or Create the Local Type include (ABAP 640) within your Global class created in SE24
- Design all the methods with the required parameters
- Activate the class with all the includes
ABAP Unit Test Class Wizard
1 Start the Local Test class Wizard
From the Class builder,
choose the menu Utilities > Test Classes > Generate, release ABAP 731 onwards OR
choose the menu Utilities > Test Class Generation
You would see the ABAP Unit test class generation wizard:
2 Select the Class Name
In the second screen, Choose the class name. The default class is selected for you.
If you have local Helper class and you are looking for test on that class, you should be able to select that by using the Local Class option. In the Local class name dropdown, choose the local class name.
3 Local ABAP Unit Test Class
In this screen, create the local test class by using the Create button. In the subsequent popup enter the class name.
There are various options on this screen:
- Generate Fixture – generate the Fixture method (SETUP, TEARDOWN)
- Generate Class Fixture – Generate the class fixture methods
- Generate Assert Equal – Method call in the test methods Assert Equal method.
- Duration Type
- Risk Level
- Super Class – Mention the global test class if you are inheriting the test class into your ABAP unit
4 Method Selection
In this popup, you would see all the active methods in the list. Choose the methods for which you want to generate the Test methods. This is one of the reason that you want to generate your class before you start the wizard.
5 Summary screen
This screen shows the summary of all the changes
Initial Test Class program lines
Based on the selected settings, the class would have this coding
Initial ABAP Unit Test class program lines
class lcl_Test_Singleton definition for testing
risk level harmless
f_Cut type ref to zcl_Test_Np_Sales_Order_Rdd. “class under test
methods: clear_Object for testing.
methods: get_Object for testing.
class lcl_Test_Singleton implementation.
create object f_Cut.
act = ro_Object
exp = ro_Object “<--- please adapt expected value " msg = 'Testing value ro_Object' * level = ). endmethod. "get_Object endclass. "lcl_Test_Singleton [/abap_code]