‎2009 Jan 13 4:29 PM
Hi,
I Build unit test and i want to test table (role_info) that i get from Fm .
if i have the problem in fro e.g. in line 1 and 3 .
I get error message that i have problem in line 1.
There is a way to get all the line that have incompatibility data like 1 3 .....?
FIELD-SYMBOLS: <rl_info> TYPE LINE OF sosp_tt_role_info,
<act> TYPE sosp_s_role_info.
lw_act-langauge = 'EN'.
lw_act-role_id = 'ADMIN'.
lw_act-role_desc = 'XXXXr'.
APPEND lw_act TO lt_a.
lw_act-langauge = 'EN'.
lw_act-role_id = 'MANAGER'.
lw_act-role_desc = 'YYYYY'.
APPEND lw_act TO lt_a.
lw_act-langauge = 'EN'.
lw_act-role_id = 'REQUESTOR'.
lw_act-role_desc = 'TTTTTT'.
APPEND lw_act TO lt_a.
lw_act-langauge = 'EN'.
lw_act-role_id = 'REVIEW'.
lw_act-role_desc = 'BBBBB'.
APPEND lw_act TO lt_a.
CALL FUNCTION 'Z_GET_ROLE_INF'
EXPORTING
iv_langu = 'EN'
IMPORTING
et_role_info = role_info
et_return = t_return.
LOOP AT role_info ASSIGNING <role_info>.
READ TABLE lt_a ASSIGNING <act> INDEX sy-tabix.
IF <rl_info> <> <act> .
l_tabix = sy-tabix.
CONCATENATE 'Wrong Output Data in line ' l_tabix '' INTO msg.
cl_aunit_assert=>assert_equals( exp = <rl_info> act = <act> msg = msg )."out in first incompatibility
ENDIF.
ENDLOOP.." In t_return i get the error message if language is unknown
P.S.
This is my first unit test program it is o.k.?
Best Regards
‎2009 Jan 13 4:39 PM
You don't need to loop through to your Actual and Expected table to find out which records are different. ABAP Unit will take care of that for you.
Like:
cl_aunit_assert=>assert_equals(
act = role_info
exp = LT_A
quit = cl_aunit_assert=>no
msg = 'Role Info is not matching' ).
Regards,
Naimesh Patel
‎2009 Jan 13 4:39 PM
You don't need to loop through to your Actual and Expected table to find out which records are different. ABAP Unit will take care of that for you.
Like:
cl_aunit_assert=>assert_equals(
act = role_info
exp = LT_A
quit = cl_aunit_assert=>no
msg = 'Role Info is not matching' ).
Regards,
Naimesh Patel
‎2009 Jan 13 4:58 PM
HI Naimesh,
Thanks,
i have 2 questions.
Just to verify.
1. In Abap unit i have to fill the table that I want to compare to hard coded, like the append i do?
2. In Abap unit how i check the input (import) of the FM or i don't do that?
Best Regards
Michael
‎2009 Jan 13 5:05 PM
1. You have to fill the Expected table. There are certains ways:
For less complex tests, you can hardcod the values.
But, when you are dealing with larger number of data, you can use FILE upload FMs to upload your expected data.
You have Fill your Input data also along with your Expected data.
For you example, you have only EN as input. So, you can directly pass that to the FM.
But when you have to pass tables than you have to fill those tables also.
Like: You have a method to Fill the Final internal table from 5 different tables.
Than you have to fill those 5 tables and the Expected table from those 5 tables.
2. Input passed to FM, doesn't need to be checked.
You have to check the Output of Method / FM / Subroutine etc.
Regards,
Naimesh Patel
‎2009 Jan 13 8:26 PM
HI ,
Thanks a lot.
You Said: You have a method to Fill the Final internal table from 5 different tables.
Maybe u have example for this kind of thing,maybe not for 5 but for 2 -3 can help.
Thanks Again.
Michael A
‎2009 Jan 13 8:39 PM
Design of my class:
Class: ZCL_GET_DATA
Methods:
GET_VBRK - Data selection from VBRK
GET_VBRP - Data selection from VBRP
GET_VBPA - From VBPA
FILL_FINAL_TABLE - Fill Final internal table by looping through VBRP and reading VBRK & VBPA.
Attributes:
T_VBRK
T_VBRP
T_VBAK
T_FINAL
My Test method implementation is like:
data lo_object type ref to ZCL_GET_DATA.
la_vbrp-vbeln = '9000019160'.
la_vbrp-posnr = '000050'.
la_vbrp-matnr = 'MAT1'.
append la_vbrp to lo_object->t_vbrp.
la_vbrk-vbeln = '9000019160'.
la_vbrk-fkart = 'ZG2'.
append la_vbrk to lo_object->t_vbrk.
la_vbpa-vbeln = '9000019160'.
la_vbpa-posnr = '000050'.
la_vbpa-kunnr = '0001000317'.
APPEND la_vbpa TO lo_object->t_vbpa.
clear la_vbpa.
la_final-vbeln = '9000019160'.
la_final-posnr = '000050'.
la_final-kunnr = '0001000317'.
la_final-fkart = 'ZG2'.
la_final-matnr = 'MAT1'.
append la_final to LT_FINAL_EXP.
lo_object->fill_final_table( ).
cl_aunit_assert=>assert_equals(
act = lo_object->t_final
exp = lt_final
quit = cl_aunit_assert=>no
msg = 'Final tables are not matching' ).
In future, due some reason (e.g. performance) you have to change the logic (i.e. instead of looping T_VBRP, loop through T_VBRK) than this type of test's result would ensure that your new logic is as good as the old.
Regards,
Naimesh Patel
‎2009 Jan 13 9:11 PM
HI Naimesh,
Thanks a lot!!!
I have last questions.
1.I see that u fill 3 tables but u check only the table t_final way?
2.You can provide the logic for :lo_object->fill_final_table( ). Method?
Please expalin how u become to this 2 code lines (the tables).
act = lo_object->t_final
exp = lt_finalThanks Again & Best Regards
Michael A.
‎2009 Jan 13 9:36 PM
1) All other methods are data selection methods. They don't contain any logic. And it would not be a good idea to write a TEST on data selection as actual data's lifetime is not constant as well as data can be different in different systems.
Like: Today in the your system VBAK (Sales Order header) contains the entry for VBELN = 1. But some one deletes that Sales Order. So, if you run your test after that deletion of Order your test will fail. This failure is because of the data not because of the change in code.
2) Logic of FILL_FINAL_TABLE is pretty simple:
LOOP AT me->t_vbrp INTO la_vbrp.
move-corresponding la_Vbrp to la_final.
READ TABLE me->t_vbrk
INTO la_vbrk
WITH KEY vbeln = la_vbrp-vbeln.
IF SY-SUBRC = 0.
la_final-fkart = la_vbrk-fkart.
ENDIF.
READ TABLE me->t_vbpa
INTO la_vbpa
WITH KEY vbeln = la_vbrp-vbeln
BINARY SEARCH.
if sy-subrc = 0.
la_final-kunnr = la_vbpa-kunnr.
endif.
append la_final to me->t_final.
clear la_Final.
ENDLOOP.
In this two parameters, I am checking the LO_OBJECT->T_FINAL which I have just filled by executing the method LO_OBJECT->FILL_FINAL_TABLE, where as LT_FINAL is my expected table. So, if any value from the actual table doesn't match to expected table this test will fail.
act = lo_object->t_final
exp = lt_final
Regards,
Naimesh Patel