hi all,
how to write unit test case?
i have a selection-screen which contain some select-options and parameter options.
for example if i have a
select-options: s_orderno for vbak-vbeln.
and i have to validate the s_orderno we have to check the order values in vbak.
so how can we write a unit test case for this validation?
Request clarification before answering.
Hello Prashant
The following sample report <b>ZUS_SDN_ABAP_UNIT_TEST_1</b> shows you a very simple ABAP Unit Test Case.
You can run the unit test by right-clicking on the report name (in tree view of SE80) and choosing context-menu function<b> <i>Execute -> Unit Test</i></b>.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ABAP_UNIT_TEST_1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_abap_unit_test_1.
TABLES: vbak.
DATA:
gt_vbak TYPE STANDARD TABLE OF vbak.
SELECT-OPTIONS:
s_order FOR vbak-vbeln.
INCLUDE zus_sdn_abap_unit_test_1_fau. " ABAP Unit Tests
START-OF-SELECTION.
PERFORM select_data.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form SELECT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM select_data .
SELECT * FROM vbak INTO TABLE gt_vbak
WHERE vbeln IN s_order.
" NOTE: Our intention was that if no order number enteres as
" selection criteria NO orders should be selected. Thus,
" our coding is wrong. This error can be detected using our
" ABAP Unit Test.
"
" Correct coding would be:
** IF ( s_order[] IS INITIAL ).
** ELSE.
** SELECT * FROM vbak INTO TABLE gt_vbak
** WHERE vbeln IN s_order.
** ENDIF.
ENDFORM. " SELECT_DATA*&---------------------------------------------------------------------*
*& Include ZUS_SDN_ABAP_UNIT_TEST_1_FAU
*&---------------------------------------------------------------------*
CLASS lcl_test DEFINITION
FOR TESTING.
PRIVATE SECTION.
METHODS:
* setup,
* teardown,
test_select_data FOR TESTING.
ENDCLASS. "lcl_test DEFINITIO
*---------------------------------------------------------------------*
* CLASS lcl_test IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_test IMPLEMENTATION.
METHOD test_select_data.
REFRESH: s_order[].
CLEAR: s_order.
PERFORM select_data.
read table gt_vbak transporting no fields index 1.
cl_aunit_assert=>assert_subrc(
exp = 4
act = syst-subrc
msg = 'Data Selection wrong - no entries expected!' ).
ENDMETHOD. "test_select_data
ENDCLASS. "lcl_test IMPLEMENTATIONPlease note that it is crucial to implement your coding in a way that it becomes testable (modularization into routines, methods, function modules).
Regards
Uwe
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.