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.

Implementing Mock Objects 3.2

mo_user_interface->popup_to_confirm( ).

* Business Logic

CASE user_answer.

WHEN 'Y'.

"Off we go!

WHEN 'N'.

RETURN.

WHEN OTHERS.

RETURN.

ENDCASE.

* Fire Missile

mo_missile_interface->tell_pi_proxy_to_fire_missile( ).

* Print Results

mo_printer->print_nuclear_smartform( )..

ENDFORM."Fire Nuclear Missile

Listing 3.2 Calling Methods of Classes

Note that the functionality has not been changed at all; the only difference is that

the calls to various external system s (the dependencies) are now handled by

classes as opposed to functions or FORM routines. All that remains untouched is

the business logic.

With the dependencies successfully el iminated, you can now set about implementing

mock objects.

3.2 Implementing Mock Objects

After you have isolated each dependency into its own class, you can change your

existing programs to take advantage of the ABAP Unit framework. There are two

steps to this:

1. Create mock objects that appear to do the sa me thing as real objects dealing

with database access and the like, but which are actually harmless duplicates

solely for use in unit tests.

2. Make sure that all the class under tests (often a unit test will use several classes,

but there is always one main one that you are testing—the class under test) is

able to use these mock objects instead of the real objects, but only when a test

is under way. This is known as injection.

143

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

Saved successfully!

Ooh no, something went wrong!