ABAP Unit Test

And don’t tell me I’m a bore. ABAP unit test worth it!

Here how it was. Once I told you about Test Driven Development methodology, but today I decided to try it in practice how it works in SAP. I created basic OData Service and decided to test it automatically.

Now I want to test it automatically. Earlier I told about SECATT. Today let’s talk about Unit testing. It such a thing which is developed in ABAP and allows to test logic inside of a program. It does not simulate user input but verifies internal procedures, methods, functions for a supposed result. For example, it should always save correct data but never allows to save incorrect data. To implement we create two methods – positive result test and negative result test.

There is the class Data Provider Class (DPC), which provides data over CRUD for OData model. It means we send HTTP GET request, for example, and it sends us back some data after authentification. We need a test which verifies the data is sent and data is equal to etalon.

For this, we need to develop a local class which tests DPC methods. Sources are below.

Benefits!

ABAP Unit Test Example

Look. Except that program can run these tests, gather statistics, run everything in the background, thereby automating quality assurance, could live together with Code Inspector; besides all of these, it can think! Well, think in its own way – it finds out what code is covered and what is not by our test cases.

ABAP Unit Test

ABAP Unit Test

The cool thing is the system shows what business-cases you have are not covered in the unit-test (test scenarios). Such hint will remind what business case is not developed in the test scenario.

Imagine tomorrow you’ll get a new support request. Somebody fix something and everything goes down. Here not to move all these broken stuff to production system we run unit-tests. Unit test will check everything in the development system, ensure this or that piece of code works not how it was supposed in test-case, And then you need to fix code in case of business logic change or fix error in your code. Don’t forget, it runs not only one particular unit-test, but dozens and hundreds of them being developed by other developers during system maintenance. Very convenient!