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.


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.


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


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


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


Do the unit test.


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.


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


Do the unit test and here we have the own message 


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


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


Let’s do the unit test.


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


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.


We have the success message.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s