ABAP Unit - Test execution
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.
Table of contents
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.