Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP Unit question

Former Member
0 Likes
608

Hello,

I am new to ABAP unit, and not really sure on how I can execute one ABAP unit test script.

Let's say I have the below code (extracted from SAPBC401_PRJD_ABAP_UNIT program in SAP ECC 6.0 system (SP9).


**&---------------------------------------------------------------------
**
**& Report  SAPBC401_PRJD_ABAP_UNIT
**&
**&---------------------------------------------------------------------
REPORT  sapbc401_prjd_abap_unit.

CLASS myclass DEFINITION.
  PUBLIC SECTION.
    CLASS-DATA text TYPE string.
    CLASS-METHODS set_text_to_x.
ENDCLASS.

CLASS myclass IMPLEMENTATION.
  METHOD set_text_to_x.
    text = 'U'.
  ENDMETHOD.
ENDCLASS.

* Test classes
CLASS mytest DEFINITION FOR TESTING.
  PRIVATE SECTION.
    METHODS mytestmethod FOR TESTING.
ENDCLASS.

CLASS mytest IMPLEMENTATION.
  METHOD mytestmethod.
    myclass=>set_text_to_x( ).
    cl_aunit_assert=>assert_equals( act = myclass=>text
                                    exp = 'X' ).
  ENDMETHOD.
ENDCLASS.

The simple question is, how I can execute the

mytestmethod

from

mytest

class?

If I just execute the above code using F8, I believe nothing is executed right?

I tried to append the below code, but it is also only executing the method in that particular class (not in the test case class).


start-of-selection.
myclass=>set_text_to_x( ).

Please help me to start...

Thanks in advanced.

rgs,

hiroshi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
517

PS: I have searched the below link, but still not understand how to execute a simple AUnit script.

/people/thomas.weiss/blog/2004/12/17/a-spotlight-on-abap-unit-part-1

http://help.sap.com/saphelp_nw04/helpdata/en/98/7e1440a1c32402e10000000a1550b0/frameset.htm

Message was edited by:

hiroshi ochi

3 REPLIES 3
Read only

Former Member
0 Likes
518

PS: I have searched the below link, but still not understand how to execute a simple AUnit script.

/people/thomas.weiss/blog/2004/12/17/a-spotlight-on-abap-unit-part-1

http://help.sap.com/saphelp_nw04/helpdata/en/98/7e1440a1c32402e10000000a1550b0/frameset.htm

Message was edited by:

hiroshi ochi

Read only

0 Likes
517

Hello Hiroshi,

in general ABAP Unit tests are executed via a test driver. The class cl_aunit_task is however not released for public use. It is integrated in some SAP services and tools. E.g. in transaction SE38 you may invoke tests via menu execute/unit Tests.

ABAP Unit tests of SAP programs in customer environments are a special case however, they are disabled. The tests in package SABP_UNIT_SAMPLE are the only exception.

You may write and use our own tests of course.

Regards

Klaus

https://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Unit

Read only

0 Likes
517

Dear Klaus,

Thanks very much! The link is very useful.

I implemented the below class for test, and now I got the idea how to continue!

 
class ZCL_WALLET definition
  public
  final
  create public .

*"* public components of class ZCL_WALLET
*"* do not include other source files here!!!
public section.

  data LIQUIDITY type I .

  methods CHECK_LIQUIDITY .
  methods GET_LIQUIDITY
    returning
      value(RE_LIQUIDITY) type STRING .
  methods PUT_IN
    importing
      !EUROS type I .


REPORT  Z_MAIN_ABAPUNIT.
class lcl_Wallet_Test definition for testing. "#AU Risk_Level Harmless

  private section.

    methods check_Liquidity for testing.

endclass.

class lcl_Wallet_Test implementation.

method check_Liquidity.
  data:
    my_Wallet type ref to zcl_Wallet,
    liquidity type i.

  create object my_Wallet.
  liquidity = my_Wallet->get_Liquidity( ).

  cl_Aunit_Assert=>assert_Equals(
    act = liquidity
    exp = 1 "purposely put 1 to show error
    msg = 'New wallet assumed empty' ).

  my_Wallet->put_In( euros = 12 ).
  cl_Aunit_Assert=>assert_Equals(
    act = my_Wallet->liquidity
    exp = 12
    msg = 'As many euros as put in before' ).
endmethod.

endclass.