To run ABAP Unit tests with code coverage measurement, do the following:
Procedure
Start a code coverage measurement. Choose Coverage AsABAP Unit Test from the context menu of the ABAP editor or Project
Explorer. The coverage display appears separately from the ABAP Unit
results display, in the ABAP Coverage
view. The view shows you the code coverage that was achieved by running the ABAP Unit tests.
Use the View Menu of the ABAP Coverage view to switch to branch coverage or procedure (processing block) coverage.
Click on a class, method, or other processing block in the ABAP Coverage view to navigate
to the code.
There, you can see the coverage at the source-code level. You can easily
detect gaps in your testing:
Green shading: Lines of code that were executed during the coverage measurement. In
branch coverage, conditional statements that evaluated to both true and
false during testing.
Red shading: Lines of code that were not executed at all during the coverage
measurement.
Yellow shading: Branches that were executed, but which did not evaluate to both
true and false.
Move the cursor over a line of code to see how many times the line was executed during the
coverage measurement. In branch coverage, you'll see how often the branch
resolved to 'true' and 'false'.
Once you are in the code-level coverage display, you can navigate as usual
(with F3). The code coverage shadings are applied to the code
you navigate to as well.
Results
Note
If there is an ABAP Unit assertion, then ABAP Developer Tools shows you the ABAP Unit Runner view first, instead of the ABAP Coverage view. Click on the ABAP Coverage icon to open the coverage view, if it is not open. The coverage measurement will be incomplete, in this case.
By default, code coverage is shown to you as statement coverage by program and processing block (method, function module, subroutine).
In the processing block view, coverage is shown for all processing blocks of the tested ABAP programs, regardless of whether code in a processing block was actually exercised by a test. You can therefore see where you still need to do testing.
The source code display is keyed to the type of coverage you are displaying in the ABAP Coverage view:
In statement coverage, every executable line is shaded either green or red. Green shows you that the line was run. Red shows you that the line was never executed.
If you have chosen branch coverage, then branches in your code are shown as red if they were not executed at all. Branches are green if they were run and resolved to both 'true' and 'false'. Branches are yellow
if they were run but resolved only to one condition, true or false.
If you have chosen procedure coverage, then procedure entry points are shown as green or red to show whether they were called or not.