Application Development 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: 

How to double a methode in Unit-Test

markus_lauxen
Member
0 Kudos

Hello,

i want to test a Methode that calls a provate Methode of the same class. This provate Methode i want to double, using the double Framework.

The Problem i face is, how to tell SAP to use the doubled Methode?

Can anybod help me?

What i got so far is:

DATA: lo_double TYPE REF TO z_cl_double.

lo_double ?= cl_abap_testdouble=>create( 'Z_IF_ADAPTER' ).

cl_abap_testdouble=>configure_call( lo_double )->returning( '10' )->ignore_all_parameters( ).
lo_double->b( ).

But how to tell my class to use the doubled Methode?

Thanks a lot,

Markus

2 REPLIES 2

johannes_konings
Participant
0 Kudos

Here is a little example. Does this help?

CLASS tcl_testdouble DEFINITION FOR TESTING
RISK LEVEL HARMLESS
DURATION SHORT.

  PRIVATE SECTION.
    METHODS test_data_call FOR TESTING.
ENDCLASS.

CLASS tcl_testdouble IMPLEMENTATION.
  METHOD test_data_call.
    DATA lt_t000_act TYPE STANDARD TABLE OF t000.
    DATA lt_t000_exp TYPE STANDARD TABLE OF t000.

    lt_t000_act = VALUE #( ( mandt = '000' )
                           ( mandt = '001' ) ).

    DATA lo_testdouble_data TYPE REF TO zjkif_testdouble_data.

    lo_testdouble_data = CAST #( cl_abap_testdouble=>create(
                            object_name = 'zjkif_testdouble_data'
*                            double_name =
                        ) ).

    cl_abap_testdouble=>configure_call( double = lo_testdouble_data )->returning( value = lt_t000_act  ).
    lo_testdouble_data->get_t000_data( ).

    DATA(lo_cut) = NEW zjkcl_testdouble( lo_testdouble_data ).

    DATA(lt_t000) = lo_cut->get_t000_data( ).

    lt_t000_exp = VALUE #( ( mandt = '000' )
                           ( mandt = '001' ) ).

    cl_abap_unit_assert=>assert_equals(
      EXPORTING
        act                  = lt_t000    " Data object with current value
        exp                  = lt_t000_exp    " Data object with expected type
    ).

  ENDMETHOD.

ENDCLASS.

PRAGSMATIC
Participant
0 Kudos

Did you find the answer markus.lauxen ?
I am searching for the same on how to mock another method B of the same CUT class which is called by A