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.

3

ABAP Unit and Test-Driven Development

cause tests to pass and fail seemingly at random, and you wouldn’t know if you

were coming or going.

This method cannot have any parameters—you will get an error if you try to give

it any—because it must perform the exact same task each time it is run, and

importing parameters might change its behavior. The code for defining the SETUP

method is very simple:

METHODS: setup,

Defining the Actual Test Methods

After defining the SETUP method, you’ll move onto defining the actual test methods.

At this stage, you haven’t actually written any production code (i.e., the code

that will actually run in the real application), and all you have is the specification.

Therefore, next you’re going to create some method definitions with names that

will be recognizable to the person who wrote the specification (Listing 3.11). The

FOR TESTING addition after the method definition says that this method will be

run every time you want to run automated tests against your application.

return_a_bom_for_a_monster FOR TESTING

make_the_monster_sing FOR TESTING

make_the_monster_dance FOR TESTING

make_the_monster_go_to_france FOR TESTING

Listing 3.11 Unit Test Methods

These are the aims of the program to be written (sometimes these are called use

cases), because you want to be sure the application can perform every one of these

functions and perform them without errors. This is why you need the unit tests.

Implementing Helper Methods

The last step in defining the test class is to implement helper methods. The purpose

of helper methods is to perform low level tasks for one or more of the actual

test methods; in normal classes, the public methods usually contain several small

private methods for the same reason. Help er methods usually fall into two categories:

왘 Helper methods that contain boilerplate code that you want to hide away

(because although you need this code to make the test work, it could be a distraction

to someone trying to understand the test)

152

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

Saved successfully!

Ooh no, something went wrong!