14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2

New Language Features in ABAP 7.4

method defined in the interface, even if you were never going to call that method

at any point in your test class. An example of this is shown in Listing 2.73.

CLASS lcl_mock_monster DEFINITION FOR TESTING.

PUBLIC SECTION.

INTERFACES if_really_big_standard_interface.

ENDCLASS.

CLASS lcl_mock_monster IMPLENTATION.

METHOD one_i_want_to_use.

ENDMETHOD.

METHOD one_i_do_not_want.

ENDMETHOD.

METHOD another_i_do_not_want.

ENDMETHOD.

Etc.

Listing 2.73 Defining and Implementing an Interface in a Test Class before 7.4

From 7.4 on, however, you can write something like Listing 2.74 in your test

class. Now, you only have to create implementations of the methods the real class

actually uses—that is, not all the blank ones.

CLASS lcl_mock_monster DEFINITION FOR TESTING.

PUBLIC SECTION.

INTERFACES if_really_big_standard_interface

PARTIALLY IMPLEMENTED.

ENDCLASS.

CLASS lcl_mock_monster IMPLENTATION.

METHOD one_i_want_to_use.

ENDMETHOD.

ENDCLASS.

Listing 2.74 Defining and Implementing an Interface in a Test Class in 7.4

2.9.2 Coding Return Values from Test Doubles

Usually, when performing unit tests yo u have some test doubles (mock objects)

that return hard-coded values based upon other hard-coded values. Prior to ABAP

7.4, you would end up with something that looks like the code in Listing 2.75.

METHOD get_monster_chemical_dose.

IF id_chemical_group = 'TRANSLYVANIA' AND

id_monster_strength = 35 AND

id_chemical_type = 'SNAILS'.

rd_chemical_dosage = '350'.

ENDIF.

132

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

Saved successfully!

Ooh no, something went wrong!