cancel
Showing results for 
Search instead for 
Did you mean: 

how to write unit test case?

03-15-2006 8:31 PM
1582 views 9 comments
0 Likes
SAP Managed Tags
Subscribe

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?

0 Likes

Accepted Solutions (0)

Answers (3)

Answers (3)

uwe_schieferstein
Active Contributor
0 Likes

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 IMPLEMENTATION

Please note that it is crucial to implement your coding in a way that it becomes testable (modularization into routines, methods, function modules).

Regards

Uwe

Former Member
0 Likes

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

Former Member
0 Likes

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?

Former Member
0 Likes

hi Ashish,

thanks for u r answer. how it looks in the real time?

it is same as u answered? or in any other way? if there is anyother way plz giveme details.

Former Member
0 Likes

Hi Prashanth,

It will be the same way as Ashish gave,probably couple of them more testing scenarios..

Former Member
0 Likes

i mean to ask u is whether we write the test cases theoretically as u written one by one <b>or</b> there is any graphical representation is there?

Former Member
0 Likes

Hi,

Generally it is theoritically written,but some times there may be screen shots also.

Former Member
0 Likes

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.

Former Member
0 Likes

Hi Ashish,

I am in SD and unaware of SD testing. I know we have test plans,test cases and scripts.

What will each one contains, i mean what exactly test plans have? Can you give overview of how testing process takes place.

Regards

Potluri