This is a test message to test the length of the message box.
ABAP Tools Work with Eclipse
Created by Software-Heroes

ABAP Tools - Quick Actions und Highlighting (ABAP Unit)


With the last release of the ABAP Development Tools, Quick Actions were added for ABAP development in the ABAP Unit area. Here we take a closer look at them.

In this article we will look at the new quick actions and code highlighting in the ABAP Unit area. Some features are currently only offered in the ABAP Environment in the BTP, but will certainly be downported to On-Premise in the future.



In the ABAP Development Tools Release 3.42, the quick actions were introduced in the ABAP Unit area. These actions are intended to take some of the work off your hands when writing unit tests and make you faster as a developer. Quick Actions are usually icons or buttons integrated into the code that trigger further actions related to the current line or selection.



First of all, we need a small class with which we can demonstrate the various options. To do this, we define a simple class with two public methods.

CLASS zcl_bs_demo_quick_actions DEFINITION

    METHODS concatenate_string
      IMPORTING id_text1         TYPE string
                id_text2         TYPE string
      RETURNING VALUE(rd_result) TYPE string.

    METHODS adding_numbers
      IMPORTING id_number1       TYPE i
                id_number2       TYPE i
      RETURNING VALUE(rd_result) TYPE string.

CLASS zcl_bs_demo_quick_actions IMPLEMENTATION.
  METHOD concatenate_string.
    rd_result = id_text1 && id_text2.

  METHOD adding_numbers.
    rd_result = id_number1 + id_number2.


The first method joins two strings and the second method calculates the sum of two numbers. We will use both methods for our tests.


Quick Actions

In the first step, let's look at the Quick Actions, how you configure them and how you can use them for yourself.



You can find the Quick Actions in the general settings in the menu under "Window -> Preferences", then in the dialog under the tree "ABAP Development -> ABAP Unit -> Code Minings".


There you can activate various options; in our example we activate all functions. In order for the functions to take effect, you should restart Eclipse.


Create test

Let's now switch to the "Test Classes" tab to get to the test classes area, where our test cases are usually defined. You will already find the first action there.


If you click on the action, the corresponding test coding is created; this corresponds to the corresponding templates from Eclipse. In the future, suitable test methods for our public methods could be defined here using AI, for example. The result now looks like this.


In the next step, we implement two test cases to have some test coding. The first test case will run on green (successful) and the second on red (faulty). The corresponding implementation of the test class is as follows:


    METHODS run_mathematics FOR TESTING.
    METHODS run_strings     FOR TESTING.

CLASS ltc_my_unit_test IMPLEMENTATION.
  METHOD run_mathematics.
    DATA(lo_cut) = NEW zcl_bs_demo_quick_actions( ).

    DATA(ld_result) = lo_cut->adding_numbers( id_number1 = 10
                                              id_number2 = 5 ).

    cl_abap_unit_assert=>assert_equals( exp = 15
                                        act = ld_result ).

  METHOD run_strings.
    DATA(lo_cut) = NEW zcl_bs_demo_quick_actions( ).

    DATA(ld_result) = lo_cut->concatenate_string( id_text1 = `Hello`
                                                  id_text2 = `ABAP Unit` ).

    cl_abap_unit_assert=>assert_equals( exp = `Hello ABAP Unit`
                                        act = ld_result ).


Execute test

Now that we have activated the coding, the next quick actions appear, depending on what you chose during configuration.


We can now execute individual test cases or the entire test class using the various "Run" buttons. In the first example, we only execute the RUN_MATHEMATICS method and the result is displayed directly in the source code.


You can find the status and runtime on the method, and the number of test cases executed and the overall status on the test class. As a second test case, we now execute all test cases in the test class. The corresponding status can now be viewed.


You can then basically start fixing the bug in the method and execute it until the result is correct. This means that all methods do not have to be executed each time to validate the delta.



The second function in this article covers code highlighting in ABAP Unit.



You can find the configuration in the general settings in the menu under "Window -> Preferences", then in the dialog under the tree "ABAP Development -> ABAP Unit -> Test Code Highlighting".


Here you can activate the various settings again and later you will have the option of setting the colors for the individual options.



What effects do the settings have? You have already seen the effects above and here is the screenshot again.


The individual components of your test code are now highlighted in color, depending on the object. If you move the mouse over the highlighted block, you will receive information about it.



This means that you now have two additional functions available in the ADTs to quickly and easily write and execute unit tests and analyze the test code. The functions certainly have potential for further AI features in the future.



SAP Help - How to Write ABAP Unit Tests

Included topics:
ToolsADTEclipseQuick Actions
Comments (0)

And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.

ABAP Tools - Working with Eclipse (CDS Templates)

Category - ABAP

Did you select the wrong CDS template when creating the view? Here's a little tip to correct the view in ABAP afterwards.


ABAP Tools - Configure Tool Bridge

Category - ABAP

Let's take a look at what the Tool Bridge is in the ABAP Development Tools and how you can easily configure it.


ABAP Tools - Work with Eclipse (Execute object)

Category - ABAP

In this article a little tip for starting objects directly, without having to go through the display of the object.


ABAP Tools - Work with Eclipse (Table creation)

Category - ABAP

In this article we will go over the flow for creating tables in the ABAP Development Tools and how you can easily design it.


ABAP Tools - Work with Eclipse (Source code compare)

Category - ABAP

Here we look at how we can use the ABAP Development Tools to compare source code, both across systems and the latest versions.