14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3

ABAP Unit and Test-Driven Development

The important point to note is that these are not finished products, so installing them is

not like installing the sort of SAP add-on you pay for. It is highly likely that you will

encounter bugs and that the tool will not do 100% of what you want it to do. In both

cases, I strongly encourage you to fix the bug or add the new feature yourself and then

update the open-source project so that the whole SAP community benefits.

The very first open-source project you will need to install is SAPlink, which will help you

to download any others you need easily. You can get SAPlink at www.saplink.org.

Good object-oriented design recommends that virtually every class has its public

signature defined via an interface. The reasons for this are too many and too complicated

to go into here, but suffice it to say that this helps you follow the OO

principle of favoring composition ove r inheritance. mockA works by using

classes that have interfaces describing their signature.

Listing 3.26 adapts the demonstration program in the mockA download package

to the running example.

METHOD mocking_framework_test.

* Local Variables

DATA: lo_mocker

TYPE REF TO zif_mocka_mocker,

ld_name

TYPE abap_abstypename

VALUE 'YIF_MONSTER_SIMULATOR',

lo_monster_simulator

TYPE REF TO yif_monster_simulator,

lf_has_been_called TYPE abap_bool,

ld_scariness

TYPE string.

lo_mocker = zcl_mocka_mocker=>zif_mocka_mocker~mock(

ld_name ).

given_monster_details_entered( ).

lo_mocker->method( 'CALCULATE_SCARINESS'

)->with( i_p1 = ms_input_data

)->returns( 'REALLY SCARY' ).

lo_monster_simulator ?= lo_mocker->generate_mockup( ).

ld_scariness = lo_monster_simulator->calculate_scariness( ms_input_

data ).

lf_has_been_called = lo_mocker->has_method_been_called( 'CALCULATE_

SCARINESS' ).

168

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!