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 first step is to break up the dependencies. In this section, you will learn how

to do exactly that, a process that involves two basic steps:

1. Looking at existing programs to identifysections of code that are dependencies

(and are thus candidates to be replaced by mock objects during a test)

2. Changing your production code to se parate out the concerns into smaller

classes that deal with each different type of dependency

3.1.1 Identifying Dependencies

Listing 3.1 is an example of a common AB AP application. In this case, our good

old friend the baron (remember him from Chapter 2?) does not want any neighboring

mad scientists building monsters and thus encroaching on his market, so

as soon as hears about such a competitor he drops a nuclear bomb on him (as any

good mad scientist would). Listing 3.1 illustrates this by first getting the customizing

settings for the missiles and making sure they are ready to fire, then confirming

with the operator that he really wants to fire the missile, then firing the

missile, and finally printing out a statem ent saying that the missile was fired. At

almost every point in the code, you will deal with something or somebody external

to the SAP system: the database, the operator (user), the missile firing system,

and the printer.

FORM fire_nuclear_missile.

* Read Database

CALL FUNCTION 'READ_CUSTOMISING'.

* Query Missile Sensor

CALL FUNCTION 'GET_NUCLEAR_MISSILE_STATUS'.

* Business Logic

IF something.

"We fire the missile here

ELSEIF something_else.

"We fire the missile there

ENDIF.

* Ask user if he wants to fire the missile

CALL FUNCTION 'POPUP_TO_CONFIRM'.

* Business Logic

CASE user_answer.

WHEN 'Y'.

"Off we go!

140

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

Saved successfully!

Ooh no, something went wrong!