ABAP Unit Test Class Wizard

By | July 22, 2014 | ABAP Objects, ABAP Unit Test | 12,389 | 6

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.

ABAP Unit

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:

  1. ABAP Unit Test Driven Development Basic Example
  2. ABAP Unit Test Driven Development Basics
  3. ABAP Unit Test Fixture methods
  4. ABAP Unit Test Global class usage
  5. ABAP Unit Test Wizard to generate Test class – This article
  6. ABAP Unit Test Real time example
  7. 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
duration short
risk level harmless
.
*?
*?
*?
*?lcl_Test_Singleton
*?

*?f_Cut
*?

*?ZCL_TEST_NP_SALES_ORDER_RDD
*?

*?
*?X
*?

*?
*?
*?X
*?

*?

*?

*?

private section.
* ================
data:
f_Cut type ref to zcl_Test_Np_Sales_Order_Rdd. “class under test

methods: setup.
methods: teardown.
methods: clear_Object for testing.
methods: get_Object for testing.
endclass. “lcl_Test_Singleton

class lcl_Test_Singleton implementation.
* ========================================

method setup.
* =============

create object f_Cut.
endmethod. “setup

method teardown.
* ================

endmethod. “teardown

method clear_Object.
* ====================

endmethod. “clear_Object

method get_Object.
* ==================

cl_Abap_Unit_Assert=>assert_Equals(
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]

Table of Content – ABAP Unit

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

6 Comments

  • Nathan Jones

    I do use the wizard to get started, but find the methods it generates not very useful as it binds it to the method not a specific test scenario.

    I really should use test classes more that I do as I’ve found them more than useful and have found more bugs in my code which I wouldn’t have done until QA or even production.

    That said, it’s remembering to use them and enforce the discipline which at times due to projects and time constraints is not always possible.

    Nathan

  • Hello Nathan,

    Agree with you on the both points – Wizard is a good start but not at what we would have expected.

    Also the Test bring the bugs out and forces us to think for all different scenarios. So, we would implement the missed code – like forgotten ELSE part of some IF .. ENDIF which would cause incorrect status to be set.

    Thanks,
    Naimesh Patel

  • Wouter

    Unit Test might seem a lot of work in the beginning – but you quickly see the benefits and you’ll get a hang of it.
    We also use the DAO concept and the TDD approach ( nut not purely TDD to be honest, if you tried TDD it changes your mindset of developing in a better way )

  • NorthernGuy

    I have to say, I use Abap Unit more and more lately. It’s a bit more work in the beginning, as OO concepts in general, but pays off later when you need to change your development or add some more features.

    TDD is an extremely interesting concept, but found it hard to follow purely in business applications.

  • Hello Wouter & NorthernGuy,

    Indeed, TDD is extremely interesting. But you can get lost while implementing as well.

    As part of the Agile methodology, the TDD can be applied via Pair-Programming. As part of the pair programming, one developer would build the Test and other developer would guide where as the other developer would build the logic and would try to make sure all tests are successful.

    Alongwith this, other advantage of pair programming is knowledge sharing.

    But, it would be very costly, as you have now two developers working on the same program with added TDD cost. It would be very beneficial in long run, though.

    Thanks,
    Naimesh Patel

  • NorthernGuy

    Yes, I have read about Pair-Programming. But for me working as a freelance consultant not feasible, I guess.

    But the idea is good. Especially if you develop a product/framework etc…

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.