In this blog we would like to introduce two open source helpers to create test data for abap unit tests.
Regardless of using the test first or test last approach in ABAP, we have to provide test data for our unit tests.
This process can be very time consuming depending on what has to be provided.
Imagine your method under test has a “simple” signature with an obligatory table of flights as importing parameter. This table must contain n lines, to reproduce a bug in coding.
Currently you would be forced to enter each line and each field-value combination manually by yourself, to achieve something like this:
lt_flights = VALUE #( ( carrid = 'AA' fldate = '20170208' price = '422.94' currency = 'USD' ) ( carrid = 'LH' fldate = '20170307' price = '431.94' currency = 'USD' ) ...
As often test data can be already viewed in debugger during bug investigation,
it would be nice to have a feature which exports this already given data from current debugging session context in such a convenient way, that this export can be used very easy in our ABAP coding.
Therefore we have developed two nice debugger enhancements.
One enhancement is used to export table data and the other export data from structures (which also could be very long) .
Table data export
Here you can see how values of an internal table can be “exported” very easy during debugging.
For internal tables you have to switch to ALV view in debugger tab “Tables”. There you will find a new button “Data for ABAP View”:
Clicking on it would bring up a window, where you can choose a line wrap for test data generation:
After that test data is presented and can be copy pasted:
Structure data export
For exporting long structure data you need to view the structure in the debugger tab “Structures”.
Proceed by clicking on the “Services of the Tool”:
Then choose the new option “Data for ABAP View”:
From here it is the same procedure as for internal table (see above).
We have been searching for a lightweight way to enhance the “new” debugger, to provide needed functionality.
Lightweight means, achieving the goal without a modification or a copy paste of SAP function groups.
Unfortunately we haven’t found any useful customer exits in SAP ABAP debugger coding.
So we decided to use the enhancement framework and it’s implicit enhancement capabilities.
You will find one enhancement for table data view (Enhancement zenh_table_values) and one enhancement for structure data view (Enhancement z_struc_v_build_services_menue).
Corresponding for each enhancement there will be one ABAP class for table data enhancement (Class ZCL_DEBUG_DATA_VIEW_TABLE_ENH) and one class for structure data enhancement (Class ZCL_DEBUG_DATA_VIEW_STRUC_ENH).
There is also the report Z_DEBUGGER_DATA_VIEW_EXT_DEMO included in the package to give you an easy way of checking the described functionality. Just place two breakpoints in it, run it and try to use the new debugger functionality.
Our implementation is using class CL_DEMO_OUTPUT and class CL_DEMO_INPUT.
Those two classes are marked as only for demonstration programs and can’t be used in production programs.
As we write tests in development systems and usually get tesatdata from test systems, no productive systems are involved.
Nevertheless it is planned to provide own Dynpros, see section “Possible enhancements to current solution”.
As we use the new VALUE operator, the minimum ABAP version you need is a 7.40.
The demo report is using SFLIGHT table for data selection. If this table is empty in your system, the demo report will be useless. So you can check functionality with any equal approach.
How to install to your system
Here you will find all the needed coding:
Please use abapGit to get this coding to your system.
Pull Requests (and Issues) on GitHub are welcome.
Possible enhancements to current solution
– SUPPORT for older SAP ABAP releases
– UI – positive list for fields which should be mapped (own Dynpro needed)
– UI – negative list for fields which should be ignored, for example client (own Dynpro needed)
– Replace UI from CL_DEMO_OUTPUT
– Eclipse PlugIn