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.

Summary 3.6

Whatever you want to call these types of automated tests, they usually involve

several methods—and often several clas ses as well—all working together. An

example of this is shown in Listing 3.30.

*--------------------------------------------------------------*

* Low-Level Test Implementation Methods

*--------------------------------------------------------------*

"GIVEN.........................

given_monster_details_entered,

"WHEN..........................

when_bom_is_calculated,

"THEN..........................

then_resulting_bom_is_correct,

Listing 3.30 The GIVEN/WHEN/THEN Pattern for Unit Tests

As you can see in the preceding code, unit test methods that follow the behaviordriven

development approach have three parts:

왘 GIVEN describes the state of the system just before the test to be run.

왘 WHEN calls the actual production code you want to test.

왘 THEN uses ASSERT methods to test the state of the system after the class under

test has been run.

Use Natural Language

A test method is supposed to be able to be viewed by business experts to see if the test

matches their specifications, so it has to re ad like natural language. Often, if business

experts see even one line of ABAP, their eyes glaze over and you have lost them for

good.

3.6 Summary

Mountain climbers will tell you their pastime is not easy, but it is all worth it once

you have achieved the incredibly difficult task of climbing the mountain and are

standing on the summit, on top of the wo rld, able to see for miles. It may not

seem similar on the surface, but unit testing is like that. It’s not easy at all—quite

the reverse—but once you have enabled yourexisting programs with full test coverage

and you create all new programs using this methodology, then you too suddenly

have a much-improved view.

173

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

Saved successfully!

Ooh no, something went wrong!