This is a test message to test the length of the message box.
Login
ABAP Unit Test Execution
Created by Software-Heroes

ABAP Unit - Test execution

283

What options are there for executing ABAP Unit and what hidden functions might you not know about? More details about the different modes in this article.



After you have written your unit tests, it is all about executing the tests and validating the results. In this article, we will take a closer look at how you can execute the tests and which hidden functions there are to make your tests easier.

 

Introduction

Whether you create your unit tests first using Test Driven Development (TDD) or complete your code with unit tests afterwards, in the end it is always about executing the tests and obtaining a result. The various start options are available to you for this. Last week we introduced you to the Quick Action and looked at how it can speed up your development. The ABAP Quick Actions are not currently available in older releases, but there is an alternative that we want to address in this article.

 

Preparation

We are therefore expanding our example from last week with an additional test class that looks like this. The special feature here is that the class has a high risk level and the execution time is long because we are executing more actions here.

CLASS ltc_low_runner DEFINITION FINAL
  FOR TESTING RISK LEVEL CRITICAL DURATION LONG.

  PRIVATE SECTION.
    METHODS run_more_tests FOR TESTING RAISING cx_static_check.
ENDCLASS.


CLASS ltc_low_runner IMPLEMENTATION.
  METHOD run_more_tests.
    DATA(lo_cut) = NEW zcl_bs_demo_quick_actions( ).

    DO 500 TIMES.
      DATA(ld_number) = sy-index.
      DATA(ld_expectation) = ld_number + ld_number.

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

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

    ENDDO.
  ENDMETHOD.
ENDCLASS.

 

Options

Let's take a look at the options available using the "Run As" option. There are two options available. That's why we want to look at all the options afterwards.

 

Preview

If you call up the preview (CTRL + SHIFT + F9), only all unit tests of the object or all selected objects are displayed. In this mode no execution takes place, but you can get an overview of the existing tests here.

 

If you only want to execute one test method, you can select the corresponding test/method in the preview and find further options in the context menu.

 

Execution

When executing (CTRL + SHIFT + F10), all unit tests are started and the results are displayed. There is no restriction on the methods or tests. However, the limits registered in the system are adhered to. In our example, the test class with "Critical" was not executed and we find a warning next to it.

 

As with the preview, it is also possible to start individual test cases via the context menu. This means you don't have to run all the tests and you can check test cases that contain errors.

 

Coverage

The coverage analysis (CTRL + SHIFT + F11) starts all unit tests on the object and carries out a coverage measurement. You will then receive the result of how much of your code is covered by ABAP unit tests and also the result of the unit tests.

 

Configuration

You can control the execution or the preview via the configuration (CTRL + SHIFT + F12). In the first step, you will receive a popup where you can set the various metrics. At the same time, there is also the option of starting a trace for the unit test.

 

However, if you try to exceed the limits of the system settings here, you will receive a warning message and the "Execute" button will no longer be active. This means that only the preview of the test cases is possible.

 

Conclusion

About the preview and the execution of individual tests via the context menu; you can also use the Quick Actions in ADT, although it is a bit slower, but still possible. In addition to carrying out the coverage measurement, a trace could also be very interesting.


Included topics:
ABAP UnitABAPUnit TestsTest execution
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 Unit - Automation

Category - ABAP

When do objects break during development and what side effects can adjustments have? In this article we take a closer look at the topic.

01/05/2024

ABAP Unit - TDF (Function Double)

Category - ABAP

In this article, let's take a look at how we can deal with function modules as dependencies without testing them as well.

04/07/2023

RAP - ABAP Unit (Service)

Category - ABAP

How do you actually test the service of an interface or RAP app automatically? In this article we look at unit tests for OData services.

01/20/2023

RAP - ABAP Unit (Business Object)

Category - ABAP

At this point, we'll take a look at how we can test our RAP Business Object automatically in order to check all important functions at the touch of a button.

01/13/2023

ABAP Unit - Tips

Category - ABAP

At the end of the series, a few tips that we would like to give you along the way. This is about shortcuts and general information about the tests.

11/12/2021