Skip to Content

Test Double Framework - How to bypass the Function called in the Tested method

Hello All,

I have been using test_double framework to test & analyze the methods in our classes. Normally, since most of our methods only include select and loop statements, I was doubling the method and inserting the mock data to the environment. But one of our method is calling some functions such as "EQUIPMENT_READ" and some other functions to fill some structures. For that reason, only mocking and filling the tables in the method is not enough to pass these functions, these functions expect real deep tables to be filled in order to give some result. My question is how to bypass these functions without filling the tables with mock data or if mock data filling is required, how to handle that in the most possible way? The original method calls the below function:

call function 'EQUIPMENT_READ'
            equi_no        = ls_result-eq_number
            equi           = ls_equi
            eqkt           = ls_eqkt
            auth_no_begrp  = 1
            auth_no_iwerk  = 2
            auth_no_swerk  = 3
            eqkt_not_found = 4
            equi_not_found = 5
            equz_not_found = 6
            iloa_not_found = 7
            auth_no_ingrp  = 8
            auth_no_kostl  = 9
            err_handle     = 10
            lock_failure   = 11 ##NUMBER_OK
            auth_no_badi   = 12
            others         = 13.

In the test method although I fill the below methods, it doesnt help to fill the ls_equi & ls_eqkt since in a deep layer it still searches for some buffered tables. Test Method:

Test Method:

class-data: environment             type ref to if_osql_test_environment.                    
rt_equi = value #( ( equnr = 'TU_NUM_1' eqart = 'IDMRDTL' )
                       ( equnr = 'TU_NUM_2' eqart = 'IDMRDSU' ) ).

    environment->insert_test_data( i_data = rt_equi ).

    rt_eqkt = value #(  ( equnr = 'TU_NUM_1' spras = 'E' eqktu = 'EQUIPMENT_TXT_1')
                        ( equnr = 'TU_NUM_2' spras = 'E' eqktu = 'EQUIPMENT_TXT_2') ).

    environment->insert_test_data( i_data = rt_eqkt ).

    rt_equz = value #(  ( equnr = 'TU_NUM_1' datbi = '01012020' eqlfn = '001')
                        ( equnr = 'TU_NUM_2' datbi = '01012020' eqlfn = '001') ).

    environment->insert_test_data( i_data = rt_equz ).
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Aug 07 at 02:59 PM

    You must not use Open SQL Test Double Framework for that. It should only be used if your tested method has an Open SQL statement.

    Instead, you must have a method which wraps EQUIPMENT_READ, and which returns only the components used. You can then easily stub this method in your test class.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 10 at 07:17 AM

    Hello Sandra,

    Thanks for the reply. May I learn how can I do that? Can you share a link that I can follow through?

    Add a comment
    10|10000 characters needed characters exceeded

    • You need to wrap that Call Function inside a method. Lets call it method get_equipment_info() wich will have the same parameters as the FM and you put teh FM inside, that is why is called a "wrapper". This for the real code, but then you need to be able to create another implementation of the same method for the test double. That will be something like this

      METHOD get_equipment_info.

      This is done using an Interface. You create an interface with that method so the real class implement the real get_equipment_info() and if it's a test clase it will implement the method that I wrote before.

      How you "inject" the test double ? you can inject it in the constructor, by parameters, etc. or you can use the ABAP Test Double Framework. (NOT the Open SQL Test Double Framework)

      If you don't have any idea about what I just said. Just look for information about TEST-SEAM / TEST-INJECTION. It's not pretty and is not the "best" approach but it'll be faster for you. With this you can put a block of code and then in the test class it will replace it with wharever you put.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.