Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically create test data for ABAP Unit Tests

schmelto
Active Participant

I want to automatically create test data for ABAP unit tests for one of my classes.

In there I have a huge method with lots of imports, exports, etc.

"! <p class="shorttext synchronized">Modify payment IDOCs</p>
    "! @exception dont_create_idoc | <p class="shorttext synchronized">Don't created a payment IDOC</p>
    "! @parameter im_mestyp | <p class="shorttext synchronized">Message type</p>
    "! @parameter im_reguh | <p class="shorttext synchronized">Payment data from the payment program</p>
    "! @parameter im_regud | <p class="shorttext synchronized">Transfer data form printing</p>
    "! @parameter im_flag_no_replace | <p class="shorttext synchronized">SPACE=Special characters conversion required in texts</p>
    "! @parameter ex_fimsg | <p class="shorttext synchronized">FI-messages</p>
    "! @parameter ch_xavis | <p class="shorttext synchronized">Flag: Advice required</p>
    "! @parameter ch_edidc | <p class="shorttext synchronized">Control record (IDoc)</p>
    "! @parameter t_regup | <p class="shorttext synchronized">Processed items from the payment program</p>
    "! @parameter t_edidd | <p class="shorttext synchronized">Data record (IDoc)</p>
    METHODS change_idoc
      IMPORTING
        im_mestyp          TYPE edidc-mestyp
        im_reguh           TYPE reguh
        im_regud           TYPE regud
        im_flag_no_replace TYPE c
      EXPORTING
        ex_fimsg           TYPE fimsg
      CHANGING
        ch_xavis           TYPE c
        ch_edidc           TYPE edidc
        t_regup            TYPE t_regup
        t_edidd            TYPE t_edidd
      EXCEPTIONS
        dont_create_idoc.

I wonder if its possible to generate test data automatically which I can use in ABAP unit tests?

My goal would be to have for example a line in my setup method of the test class with:

reguh =  VALUE #( ... )
5 REPLIES 5

FredericGirod
Active Contributor

Yes but No, Tom 🙂

(when I learn about Abap Unit I had exactly the same idea 😉 )

You forget one of the golden rule regarding ABAP Unit : The data must not be real data

You have a second problem, your method is little bit complex for ABAP Unit, you have so many cases, it is maybe the reason why you would like to do a mass test on it.

You should do ABAP Unit on the methods used inside this method (and following Single Responsibility)

schmelto
Active Participant
0 Kudos

Thanks frdric.girod I've assumed something like this. Yes the method is really complex.

I will implement Unit Tests for less complex methods which are used inside this method

FredericGirod
Active Contributor

even if you have private/protected method you could do abap unit, even if it is bad usage.

You have to use LOCAL FRIEND stuff

Sandra_Rossi
Active Contributor

Generating test data doesn't mean generating real data. You can think of a tool which analyzes the code under test and proposes possible values for test data, combinations and so on. I don't know if such a tool exists in ABAP.

I don't have this issue because I create the tests and the test data before coding (test-driven development)

alex_geppart
Active Participant