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.
Hi
Unit Tests are defined and performed by developers. A process consists usually of several functions. Each of this function usually consists of "sub-functions" corresponding to a single method or a group of methods (if you are developing OO-based).
Unit Tests could be described as white-box tests whereas a normal tester (which should be not identical to the developer) will test entire functions (black-box tests).
You have to have the ABAP unit implemented in the code for this to be used...pls see the link from SAP help..
http://help.sap.com/saphelp_nw04/helpdata/en/a2/8a1b602e858645b8aac1559b638ea4/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c4/7c1440a1c32402e10000000a1550b0/frameset.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Soemthing like this.
Test case Heading: Check if the entered Order exist in the system.
Test Case 1: Order No which exist in SAP is entered on selection screen.
Expected Result: Order no should be validated with VBAK. And if record exist, it should continue the process.
Actual: Result: Process continued.
Test Case 2: Order which does not exist in SAP is entered on selection screen.
Expected Result: Error message 'Pls enter valid Order' should be displayed in selection screen.
Actual Result Result: Error message is displayed.
Are you looking for something like this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Prashanth,
We create all test cases as i have suggested. Expected result is what is expected from that case.
In each case you need to provide test data used to perform the test. Based upon this data and test, expected result is derived.
and actual result column is filled when you use this test case and test your code.
Expected result is theoritical but Actual result is the outcome of the test.
Usually develoeprs do not prepare test cases. These are provided by Functional Consultant which we as developers use during testing of the programs.
| 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.