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.

1

ABAP in Eclipse

To do this in Eclipse, create a new global class. At the bottom is a series of tabs,

one of which is Test Class. Note that you have not created anything in the real

class yet. Now, go to the Test Class tab, type in the word “test”, and press (CTRL)

+ (SPACE).

You are asked a question about whether you want to create a transport request or

a test class. The test class is the correc t answer, and if you choose that option,

you’ll see the content of Listing 1.13.

*"* use this source file for your ABAP unit test classes

CLASS ltcl_definition FINAL FOR TESTING

DURATION SHORT

RISK LEVEL HARMLESS.

PRIVATE SECTION.

METHODS:

first_test FOR TESTING RAISING cx_static_check.

ENDCLASS.

CLASS ltcl_ IMPLEMENTATION.

METHOD first_test.

cl_abap_unit_assert=>fail( 'Implement your first test here' ).

ENDMETHOD.

ENDCLASS.

Listing 1.13 Source File for ABAP Unit Test Class

Creating such a skeleton template for a test class isn’t the holy grail of creating

unit tests, but it follows test-driven development much better than the standard

SE80 process. Naturally, yo u need to change the generated code to fill in the

name of your test class and test method and add extra test methods as needed.

The point is that you are creating the test methods first and then copying the definition

to the real class.

As you saw in Section 1.2.3, once you have a definition you can generate the

implementation skeleton just by pressing (CTRL) + (1). What the automatic generation

is supposed to do is add a definition, such as DATA: mo_cut TYPE REF TO ycl_

monster_unit_tests. (This actually did not work for me no matter what I tried, so

I added it manually. The documentation indicates that this should be done automatically,

so it will probably be fixed in a later release.)

In the renamed first monster unit test, first define the test result, and then add

the line mo_cut->first_monster( )., which is a method in the main class that

64

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

Saved successfully!

Ooh no, something went wrong!