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: 

Abap Unit - Test double result is differnt if full test or single test

FredericGirod
Active Contributor
0 Kudos
767

Hi Team,

I start using Test double with Abap Unit ( I am used to use Mock ).

The issue is really simple, I have two test methods.

When I run both methods, the first one failed.

When I run just the first one, it success.

  METHOD new_batch_id_is_ok_01.
cl_abap_testdouble=>configure_call( o_data )->returning( '209912345' ).
o_data->get_new_batch_id( '99' ).
cl_abap_unit_assert=>assert_equals(
act = o_cut->get_new_batch_id( '2099' )
exp = '2099-12345' ).
ENDMETHOD.

METHOD new_batch_id_is_ko_01.
cl_abap_testdouble=>configure_call( o_data )->raise_exception( o_exception ).
o_data->get_new_batch_id( '98' ).
cl_abap_unit_assert=>assert_equals(
act = o_cut->get_new_batch_id( '98' )
exp = '' ).
ENDMETHOD.


the testdouble creation is in the SETUP method :

  METHOD setup.
o_data ?= cl_abap_testdouble=>create( 'ZIF_ISU_DEPLOY_BATCH_DATA' ).
o_rules ?= cl_abap_testdouble=>create( 'ZIF_ISU_DEPLOY_BATCH_RULES' ).
o_cut = zcl_isu_deploy_factory=>get_instance( )->get_batch_instance(
io_data_instance = o_data
io_rules_instance = o_rules ).
o_exception = NEW #( ).
ENDMETHOD.

Is there a clean action to be done between test double ?

BR

Fred

1 ACCEPTED SOLUTION

FredericGirod
Active Contributor
0 Kudos
641

Ok,

so the issue is not related to doubleframework. It is because I use Design Pattern SingleTon to create my O_CUT.

So when I called the second time the Get_Instance( ) from the Factory, it replies directly the first Instance created, with the O_data and O_Rules of the first Instance.

Solution replace :

    o_cut   = zcl_isu_deploy_factory=>get_instance( )->get_batch_instance(
                    io_data_instance  = o_data
                    io_rules_instance = o_rules ).
    o_cut   = new zcl_isu_deploy_batch( io_data_instance  = o_data                                                             
                                        io_rules_instance = o_rules ).
3 REPLIES 3

thalesvb
Active Contributor
0 Kudos
641

Hi, could you share (or review) get_batch_instance code?

FredericGirod
Active Contributor
0 Kudos
642

Ok,

so the issue is not related to doubleframework. It is because I use Design Pattern SingleTon to create my O_CUT.

So when I called the second time the Get_Instance( ) from the Factory, it replies directly the first Instance created, with the O_data and O_Rules of the first Instance.

Solution replace :

    o_cut   = zcl_isu_deploy_factory=>get_instance( )->get_batch_instance(
                    io_data_instance  = o_data
                    io_rules_instance = o_rules ).
    o_cut   = new zcl_isu_deploy_batch( io_data_instance  = o_data                                                             
                                        io_rules_instance = o_rules ).

FredericGirod
Active Contributor
0 Kudos
641

thanks thalesvb to helping me.

I have found my problem

BR

Fred