Hi Community !
I'd like to share a tool for unit testing me and my team have developed for our internal usage recently.
The tool is created to simplify data preparation/loading for SAP ABAP unit tests. In one of our projects we had to prepare much tables data for unit tests. For example, a set of content from BKPF, BSEG, BSET tables (FI document). The output to be validated is also often a table or a complex structure.
Hard-coding all of that data was not an option - too much to code, difficult to maintain and terrible code readability. So we decided to write a tool which would get the data from TAB delimited .txt files, which, in turn, would be prepared in Excel in a convenient way. Certain objectives were set:
...
call method o_ml->load_data " Load test data (structure) from mockup
exporting i_obj = 'TEST1/bkpf'
importing e_container = ls_bkpf.
call method o_ml->load_data " Load test data (table) from mockup
exporting i_obj = 'TEST1/bseg'
i_strict = abap_false
importing e_container = lt_bseg.
...
call method o_test_object->some_processing " Call to the code being tested
exporting i_bkpf = ls_bkpf
it_bseg = lt_bseg
importing e_result = l_result.
assert_equals(...).
...
BUKRS BELNR GJAHR BUZEI BSCHL KOART ...
1000 10 2015 1 40 S ...
1000 10 2015 2 50 S ...
...
call method o_ml->store " Store some data with 'BKPF' label
exporting i_name = 'BKPF'
i_data = ls_bkpf. " One line structure
...
...
if some_test_env_indicator = abap_false. " Production environment
" Do DB selects here
else. " Test environment
call method zcl_mockup_loader=>retrieve
exporting i_name = 'BKPF'
importing e_data = me->fi_doc_header
exceptions others = 4.
endif.
if sy-subrc is not initial.
" Data not selected -> do error handling
endif.
...
...call method o_ml->store " Store some data with 'BKPF' label
exporting i_name = 'BKPF'
i_tabkey = 'BELNR' " Key field for the stored table
i_data = lt_bkpf. " Table with MANY different documents
...
...
if some_test_env_indicator = abap_false. " Production environment
" Do DB selects here
else. " Test environment
call method zcl_mockup_loader=>retrieve
exporting i_name = 'BKPF'
i_sift = l_document_number " Filter key from real local variable
importing e_data = me->fi_doc_header " Still a flat structure here
exceptions others = 4.
endif.
if sy-subrc is not initial.
" Data not selected -> error handling
endif.
...
The code is freely available at our project page on github - sbcgua/mockup_loader · GitHub
I hope you find it useful :smile:
Alexander Tsybulsky
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
23 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 |