Wednesday, 1 January 2020

SAP Coverage Analyzer

Introduction


What is Coverage Analyzer?

SAP Coverage Analyzer is a very powerful system-wide runtime analysis tool provided by SAP for collecting, monitoring and analyzing the code coverage of test suites such as Self tests, Unit tests, integration tests and Quality tests.

What is the use of Coverage Analyzer?

A Developer can use this tool to trace programs for development purpose and a Quality Manager can use this tool to check system performance for quality assurance.

Also Read: SAP ABAP with SAP NetWeaver 7.5 - C_TAW12_750

Developer:

◉ It enables a developer to monitor processing blocks such as reports, subroutines, function-modules and methods using an efficient filtering system that facilitates the developer to filter the results based on object name, periods, users and functional areas.

◉ Determine the test coverage even for a single test run.

◉ Determine unused/redundant codes.

◉ You can check why a particular program does not attain your code coverage standards by looking at the code coverage of the processing blocks in the program. You can see which forms, methods or other processing blocks are not adequately tested.

◉ Drill down to see the branch and statement coverage in the source code of a method, form routine or other processing block.

◉ To fine-tune your tests or understand gaps in testing, you can see which branches and statements in a processing block have been executed.

Quality Manager:

◉ It enables a Quality manager to monitor system-wide execution of ABAP programs to get the summarized information on number of program executions, number of runtime errors, number of program resets.
◉ Determine the adequacy of testing done in the system.
◉ This summarized information can be formatted and reported separately according to user-group, periods and functional areas with graphical charts.

How to use Coverage Analyzer?

The usage of this tool will be explained with the below three scenarios.

1. Monitoring the first time execution of a scenario – Developer.
2. Monitoring the test suites run – Developer/Quality manager.
3. Monitoring Dumps in the code and code blocks – Developer/Quality manager.

The following steps involves creation of test data which will be used for the all the three scenarios.

◉ Create a test function module as below.(Please check reference URL)

FUNCTION ztest_scov_fm.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      MARA STRUCTURE  MARA
*"----------------------------------------------------------------------
    SELECT *
      UP TO 10 ROWS
      INTO TABLE mara[]
      FROM mara.
    WRITE /:'FM Call'.
ENDFUNCTION.

◉ Create a test report as below. Take 2 minutes to understand the code.(Please check reference URL)

*&---------------------------------------------------------------------*
*& Report  ZTEST_SCOV_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ztest_scov_report.
*&---------------------------------------------------------------------*
*&      SELECTION SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS : p_first  RADIOBUTTON GROUP g1,
             p_second RADIOBUTTON GROUP g1.
PARAMETERS : po_dump  AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
*       CLASS ztest_SCOV_class DEFINITION
*----------------------------------------------------------------------*
CLASS ztest_scov_class DEFINITION.
  PUBLIC SECTION.
    DATA i_kna1       TYPE STANDARD TABLE OF kna1.
    METHODS ztest_scov_method.
ENDCLASS.                    "ztest_SCOV_class DEFINITION
*----------------------------------------------------------------------*
*       CLASS ztest_SCOV_class IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS ztest_scov_class IMPLEMENTATION.
  METHOD ztest_scov_method.
    SELECT *
      UP TO 10 ROWS
      INTO TABLE i_kna1[]
      FROM kna1.
    WRITE /: 'Method Call'.
  ENDMETHOD.                    "ztest_SCOV_method
ENDCLASS.                    "ztest_SCOV_class IMPLEMENTATION
*&---------------------------------------------------------------------*
*&      GLOBAL DATA DECLARATION
*&---------------------------------------------------------------------*
DATA : w_dec        TYPE vbap-kbmeng,
       i_mara       TYPE STANDARD TABLE OF mara,
       w_callclass  TYPE REF TO ztest_scov_class.
*&---------------------------------------------------------------------*
*&      START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  IF p_first IS NOT INITIAL.
    WRITE /: 'First part of the code gets executed'.
    CALL FUNCTION 'ZTEST_SCOV_FM'
      TABLES
        mara = i_mara.
  ELSEIF p_second IS NOT INITIAL.
    PERFORM ztest_scov_subroutine.
    WRITE /: 'Second part of the code gets executed'.
  ENDIF.
*&---------------------------------------------------------------------*
*&      END-OF-SELECTION.
*&---------------------------------------------------------------------*
END-OF-SELECTION.
  IF po_dump IS NOT INITIAL.
    w_dec = 'xyz'.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  ztest_SCOV_subroutine
*&---------------------------------------------------------------------*
FORM ztest_scov_subroutine .
  CREATE OBJECT w_callclass .
  CALL METHOD w_callclass->ztest_scov_method.
ENDFORM.                    " ztest_SCOV_subroutine

◉ Go to SAP Menu -> Tools -> ABAP Workbench -> Test -> Coverage Analyzer or go to the transaction SCOV.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Double click on “On/Off, Status” from the Administration folder of the SCOV initial screen.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Switch on the Coverage Analyzer by clicking the “On” button. You will be prompted with a message confirming whether you want to start the analyzer or not, select “Yes” and proceed.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Select the server displayed in the ALV and start it by clicking on the start button. In this case, the server selected will be the current system i.e. the Development system.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

Switching them both on will make the Analyzer ready for monitoring all the ABAP programs in the development system.

Scenario (1/3): Monitoring the first time execution of a scenario – Developer. 


◉ To monitor the execution for the first time of the test program (ZTEST_SCOV_REPORT) that we have created, a reset of all the old execution history must be done. This can be done by double clicking on “Reset” from the Administration folder.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ In the selection screen parameter that is displayed, enter the program name (ZTEST_SCOV_REPORT) and click on “Delete Coverage Results of Selected Objects”. This will delete all the coverage results that were captured till now.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Open the folder “Display” in the left frame and double click on the “Details” under that folder. This will display a selection screen where the name of the program (ZTEST_SCOV_REPORT) should be entered and executed (F8).

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ This will display an ALV which has details of the program as shown below. Some of the details to be considered now are the Status – Signal: RED denotes no code coverage has been done since we had reset the counter in step number 2. It also displays the processing blocks, branches, statements available and others details which will be explained in detail latter.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Now execute the program (ZTEST_SCOV_REPORT) with the first radio button checked in another session. The output will be displayed as shown.

INPUT :                                                                                 OUTPUT :

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Now refresh the display in Coverage Analyzer screen.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ You can note that the status of the program would have changed. In this case it has become YELLOW denoting that the code has been processed and this processing is only average. If the code had been covered fully then the display would be GREEN.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Double click on the program. This will take you to the next screen containing detailed information on the execution as shown below. This will give you the details of the processing blocks that have been executed for a test run.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Double clicking on them will go a step deeper displaying the code that has been executed and those that have not by highlighting with green and red respectively. Double clicking Start of selection displays the below details. We had selected the first radio button for this test run and you can see the part of the code that has been executed for that radio button selection.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ This will enable a developer to monitor the coverage of his code for a single execution.

Scenario (2/3): Monitoring the test suites run – Developer/Quality manager.


Before beginning with the monitoring of test suites, the objects to be monitored have to be reset. The steps for this have been mentioned in the Scenario 1 points 1 and 2. After resetting proceed with the execution of the test scripts.

Let’s continue with the above test case to help us with this scenario. We had executed the program- ZTEST_SCOV_REPORT once and now proceed with the execution of other scenarios.

◉ Execute the program ZTEST_SCOV_REPORT with the second radio button selected.

INPUT :                                                                                 OUTPUT :

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Now according to this sample program, all its test scripts/scenario has been executed. Then finally go to SCOV screen and refresh the display. You can note that the status of the execution has changed to GREEN denoting that the execution has reached a good coverage.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Going deeper by double clicking the program into a detailed view also will show that the execution had a good coverage as all the processing blocks were covered.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Double clicking on them will go a step deeper displaying the code that has been executed and those that have not by highlighting with green and red respectively. Double clicking Start of selection displays the below details. We had selected the second radio button for this test run and you can see the part of the code that was executed in scenario 1 and also the part of the code executed for this scenario has been highlighted with green.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ This will enable a developer/Quality manager to monitor if all the test cases for a program(s) have been executed and whether that execution has covered/executed all the code of the selected program(s).

Scenario (3/3): Monitoring Dumps in the code and code blocks – Developer/Quality manager. 


Let’s continue with the above test case to help us with this scenario. We had executed the program- ZTEST_SCOV_REPORT according to the test scripts prepared for it. This scenario deals with monitoring dumps that occur in the course of executions of the test scripts.

◉ Execute the program ZTEST_SCOV_REPORT with the second radio button selected and the PO_DUMP check box checked.

INPUT :                                                                     OUTPUT : PROGRAM TERMINATED

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

◉ Go to SCOV screen and refresh the display. You can note that the status of the execution has changed to GREEN denoting that the execution has reached a good coverage.

◉ Going deeper by double clicking the program into a detailed view will show that the execution of the block END-OF-SELECTION had a dump as show below.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Online Exam

By this way we can determine the processing block where a dump occurs and their frequencies as well. If we have to find out the exact position of where a dump has/had occurred when being executed by a tester, we can just reset the counter for that program, ask them to execute it and then we’ll get to know the block where that dump occurred (as further code coverage would have been halted) and also the dump details via ST22.

With all these Scenarios, hope the usage of SCOV has been explained well.

Limitations of Coverage Analyzer?


This will have a heavy impact on the performance of the system since it starts to monitor each and every execution of programs.

Remember to switch off the Analyzer when it is not in use.

No comments:

Post a Comment