03-25-2022 10:50 AM
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 #( ... )
03-25-2022 11:29 AM
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)
03-25-2022 12:26 PM
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
03-25-2022 12:51 PM
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
03-25-2022 6:39 PM
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)
03-26-2023 11:21 AM
Hi Tom,
have you checked out this approach?:
https://blogs.sap.com/2017/12/17/abap-debugger-enhancement-or-how-to-speed-up-your-test-data-creatio...