Show TOC

Step 6: Saving and Retrieving Code Coverage ResultsLocate this document in the navigation structure

Procedure

Do you need to save your code coverage results and measurements for future reference? You can do this with the services of the code coverage repository.

Here is code for saving a code coverage result and the measurement from which it was calculated.

You need only save results in order to save both results and the measurements from which they derive.

DATA: repository TYPE REF TO if_scv_repository,
      result_id TYPE cva_uuid,
      measurement_id TYPE cva_uuid,
      measurement TYPE REF TO if_scv_measurement,
      result TYPE REF TO if_scv_result..  

* The Repository of the Coverage API is  
* responsible for all save and reload 
* operations on measurements, results, and  
* measurement series 
repository = cl_scv_coverage_api=>get_repository( ).  

* The Repository takes care that no inconsistencies in   
* the data objects of the Coverage API can occur.  For   
* this reason, you need only save results in order to  
* save the associated measurements and measurement series. 
* Saves the result and measurement 
result_id = repository->save_result( result ).  

* You can separately save a measurement if necessary.  
measurement_id = repository->save_measurement( measurement ).

* Retrieve the measurement
CLEAR measurement.
measurement = repository->load_measurement( i_id = measurement_id ).

* Retrieve the result
CLEAR result.
result = repository->load_result( i_id = result_id ). 

         

The save functions return an ID with which you can retrieve a result or a measurement. .

To retrieve a standalone measurement, you need either:

  • The ID that the repository returns when you save the measurement (method IF_SCV_REPOSITORY->LOAD_MEASUREMENT)

  • The test key of the measurement (methods IF_SCV_REPOSITORY->LOAD_MEASUREMENT and IF_SCV_REPOSITORY->FIND_MEASUREMENT_ID_BY_TESTKEY). You can obtain the test key with IF_SCV_MEASUREMENT->GET_TEST_KEY.

From a result object, you can also navigate to the associated measurement with IF_SCV_RESULT->GET_MEASUREMENT.

Finally, you can retrieve all measurements saved in the repository with the generic method IF_SCV_REPOSITORY->FIND_MEASUREMENTS. The measurements contain metadata such as time stamps, with which you could select among the set of 'found' measurements.

To retrieve a result that was generated from a standalone measurement, you need either:

  • The ID that the repository returns when you save the result (method IF_SCV_REPOSITORY->LOAD_RESULT)

  • The measurement object from which the result was generated (method IF_SCV_REPOSITORY->FIND_RESULTS_BY_MEASUREMENT).

You must save test keys or measurement and result IDs yourself, if you want to retrieve stored standalone measurements and results from the repository without using the generic FIND_MEASUREMENTS method.

Recommendation

Measurement series offer more convenient ways of accessing saved measurements and results for trend analysis and tracking.

Switch to measurement series - rather than standalone measurements - if you plan to do extensive trend analysis and tracking of code coverage.

If you do not need to calculate any more coverage results, then you can go on to finalize the measurement.

Here is the complete sample program.