2023 Oct 12 8:27 AM
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
2023 Oct 12 9:17 AM
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 ).
2023 Oct 12 9:13 AM
Hi, could you share (or review) get_batch_instance code?
2023 Oct 12 9:17 AM
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 ).
2023 Oct 12 9:19 AM
thanks thalesvb to helping me.
I have found my problem
BR
Fred