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.

Automating the Test Process 3.4

ld_class_type_to_create " Exact Class to Create

it_signature_values = lt_signature_values " Parameter Values

CHANGING co_object = co_object ). " Created Object

ENDMETHOD."Create Via Injection

Listing 3.25 CREATE_BY_INJECTION Method

If you want to drill into this even more, you can download this code at www.sappress.com/3680

and run it in debug mode to see what’s happening.

In summary, dependency injection provide s a way to set up complicated classes

while using a lot less code, which will en able you to create test classes with less

effort.

Error Handling

There is virtually no error handling in the code just discussed (except for throwing fatal

exceptions when unexpected things occur). This could be a lot more elegant—but it is

the basic principle of automating dependency injection, not elegance, that is currently

our focus.

3.4.2 Automating Mock Object Creation via mockA

Unit testing frameworks have been around for quite some time in other languages,

such as Java and C++. ABAP has joined the club rather late in the day. One

advantage of this is that ABAP develope rs can look at problems other languages

encountered—and solved—some years ago, and if they find the same problem,

then they can implement the same sort of solution without having to reinvent the

wheel. Mock objects are a great example of this: Many different mock object

frameworks for Java were born to take a lot of the pain out of the process. An SAP

developer named Uwe Kunath started an open-source project to achieve the same

solution in ABAP and called his proj ect the mockA framework. mockA can be

downloaded at https://github.com/uweku/mockA.

ABAP Open-Source Projects

There are several times where this book will refer to open-source ABAP projects that

started life on the SAP Code Exchange section of the SAP Community Network but

nowadays live on sites like GitHub. The obvious benefit of these projects is that they are

free. Some development departments have rules against installing such things, but I feel

they are just cutting off their nose to spite their face.

167

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

Saved successfully!

Ooh no, something went wrong!