ABAP UNIT TEST-2

abap-unit-test

Simple Unit Test using local class

 

 


Here the Test Unit is single method: GET_FLIGHTS of the local class LCL_FLIGHT. We call the test class LCL_TEST_FLIGHT to test the unit method  GET_FLIGHTS in abap editor. In the test class we have set the risk level and the time duration.

12

We have set the expected result & the actual result will get from the method call  and then the service class CL_AUNIT_ASSERT will compare them.

Below we have the SPFLI table records.

3

If unit test is performed from abap editor, then navigate along the menu path to do the UNIT Test.

4

So we have the expected result and the actual result matched, and hence the success message in the status bar.

5


Let’s change the carrid value to something for the select query fails but we expect the result to be 0.

6


Do the unit test.

7


So here is the unit test display screen. Shows the status as ERROR. Also shows the message and the difference between expected value and the actual value.

8


We can also provide our own error message text to be displayed in case of failed comparison.

9


Do the unit test and here we have the own message 

10


The system wide setup in Tx- SAUNIT_CLIENT_SETUP, for short duration the execution time is 60 seconds.

11


For test purpose we have added a wait command in the method execution and in the test method we have mentioned duration is short.

12


Let’s do the unit test.

13

The unit test result shows below result. We expect our method execution should take less than 60 secs but it takes more than that.

14


In some case if you test a really big method, or big FM which takes more than 1 min, then you can set the duration accordingly as MEDIUM or LONG. and do the unit test.

15


We have the success message.

16.jpg


 

Leave a Reply