21.03.2013 Views

Object Oriented ABAP

Object Oriented ABAP

Object Oriented ABAP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Introduction:<br />

Understanding "<strong>ABAP</strong> Unit"<br />

It is a best practice to modularize our programs as much as we can for better<br />

programming. If we want to check one particular module like subroutines, function modules<br />

or classes for bugs then we can do it using <strong>ABAP</strong> Unit. <strong>ABAP</strong> Unit is a tool for unit testing of<br />

<strong>ABAP</strong> programs.<br />

How to write these tests:<br />

<strong>ABAP</strong> unit is based on <strong>ABAP</strong> objects. The global class CL_AUNIT_ASSERT contains methods<br />

which can be used for testing .Tests are implemented in local classes. Inside the local class<br />

the necessary method from the global class can be called for testing. These test classes can<br />

be written inside the program for which the test is to be done. It will not affect our<br />

production code in anyways.<br />

Difference between Ordinary class and Test class:<br />

Both the test class and test method should have FOR TESTING addition.<br />

Ex:<br />

CLASS mytest DEFINITION FOR TESTING.<br />

PRIVATE SECTION.<br />

METHODS mytest FOR TESTING.<br />

ENDCLASS.<br />

Methods in CL_AUNIT_ASSERT for Testing:<br />

ASSERT_EQUALS<br />

ASSERT_DIFFERS<br />

ASSERT_BOUND<br />

ASSERT_NOT_BOUND<br />

ASSERT_INITIAL<br />

ASSERT_NOT_INITIAL<br />

ASSERT_CHAR_CP<br />

ASSERT_CHAR_NP<br />

ASSERT_EQUALS_F<br />

FAIL<br />

ABORT<br />

ASSERT_EQUALS - Checks the equality of two data objects.<br />

ASSERT_DIFFERS - Checks for the difference of two data objects.

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

Saved successfully!

Ooh no, something went wrong!