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.

Testing and Troubleshooting 1.3

does not yet exist. If you press (CTRL) + (1), you are asked if you want to create the

method in the real class, which you do . Remember, you created the test before

you created the real method, which is what test-driven development is all about.

In summary, the whole test-driven development process is faster and easier (and

the right way around) when using ABAP in Eclipse than when using the equivalent

procedure in the traditional ABAP Workbench.

Problem 2: You Cannot Tell How Much of the Program Is Being Tested

The aim of unit testing is to be as sure as humanly possible that when you change

one part of your program—be it a bug fix or adding extra functionality—the

change does not break other parts of the program. In real life, people tend to find

that a change in one area always breaks something in another area, which should

be a red flag to indicate that maybe th ere’s something wrong with creating such

fragile programs.

Unit tests enable you to perform automa ted regression tests so that when you

change even one line of code you can be sure that you have not broken something

somewhere else. Naturally, you can only be really safe if you know that every single

line of code in every routine and method in your application is subject to such

a regression test. Creating such tests in the first place is not the easiest thing in the

world, which is why so few people do it—this will be discussed much more in

Chapter 3. However, if you have seen th e light and do wish to create such tests,

the next task is to see how much of your code is actually getting tested. If that figure

turns out to be less than 100%, then see what can be done about it.

There is a tool available in Java called Clover, which measures the percentage of

code covered by unit tests. When I read about it, I thought it would be really good

for ABAP and that maybe I should write something along those lines myself. It

turns out that I don’t need to, because ABAP in Eclipse has just such a tool (and,

to be fair, so does SE80 in the latest releases of SAP NetWeaver).

In the last section, you created one te st method. Now, you’ll create the real

method, which will be tested, and then you’ll create another real method, which

will not have a corresponding unit test—as if you’re being naughty and trying to

fool yourself into thinking that creati ng methods without tests will save time.

(They! Will! Not!)

65

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

Saved successfully!

Ooh no, something went wrong!