<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unit testing database values after insertion in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745750#M2021415</link>
    <description>&lt;P&gt;What "double internal table" are you talking about? The concept of ABAP SQL Test Double is only in database.&lt;/P&gt;&lt;P&gt;Can't you ask a question with minimal reproducible code that we can copy and paste? (the same as I did)&lt;/P&gt;&lt;P&gt;Otherwise people will stop looking at your question if you give the important information only in the comments.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2023 14:45:38 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2023-08-01T14:45:38Z</dc:date>
    <item>
      <title>Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745745#M2021410</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
  &lt;P&gt;I'm trying to use unit tests for writing access database tests, but I can't find a way to validate the correctness of inserted data. I'm using the ABAP SQL Test Double Framework : &lt;EM&gt;if_osql_test_environment&lt;/EM&gt;.&lt;/P&gt;
  &lt;P&gt;I'm testing an insert method into the EKKO table, which is replace (with the framework) by the internal table MT_EKKO. While reading this table after the insert in the test environment, no new line is added. The test failed at my READ INDEX 2 on MT_EKKO. The insert return a sy-subrc of 0. &lt;/P&gt;
  &lt;P&gt;My goal is to check my new values in the MT_EKKO table to test in the future BAPI custom enhancement.&lt;BR /&gt;&lt;BR /&gt;Is there a way to look up for data changes in the double table made with the framework?&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;REPORT.&lt;BR /&gt;&lt;BR /&gt;CLASS lcl_test_bapi DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS .&lt;BR /&gt;  PRIVATE SECTION.&lt;BR /&gt;    CLASS-DATA:&lt;BR /&gt;      mo_sql_env     TYPE REF TO if_osql_test_environment.&lt;BR /&gt;    DATA:&lt;BR /&gt;      mt_ekko TYPE STANDARD TABLE OF ekko.&lt;BR /&gt;    CLASS-METHODS:&lt;BR /&gt;      class_setup,&lt;BR /&gt;      class_teardown.&lt;BR /&gt;    METHODS:&lt;BR /&gt;      setup,&lt;BR /&gt;      teardown,&lt;BR /&gt;      test_insert FOR TESTING.&lt;BR /&gt;ENDCLASS.&lt;BR /&gt;&lt;BR /&gt;CLASS lcl_test_bapi IMPLEMENTATION.&lt;BR /&gt;  "Setup and teardown&lt;BR /&gt;  METHOD class_setup.&lt;BR /&gt;    mo_sql_env = cl_osql_test_environment=&amp;gt;create( i_dependency_list = VALUE #( ( 'EKKO' ) ) ).&lt;BR /&gt;  ENDMETHOD.&lt;BR /&gt;  METHOD class_teardown.&lt;BR /&gt;    mo_sql_env-&amp;gt;destroy( ).&lt;BR /&gt;  ENDMETHOD.&lt;BR /&gt;  METHOD setup.&lt;BR /&gt;    mt_ekko = VALUE #( ( mandt = sy-mandt ebeln = '1111111111' bstyp = 'F' bsart = 'NB' aedat = '20230703' ernam = 'setup_method' ) ).&lt;BR /&gt;    mo_sql_env-&amp;gt;insert_test_data( mt_ekko ).&lt;BR /&gt;  ENDMETHOD.&lt;BR /&gt;  METHOD teardown.&lt;BR /&gt;    CLEAR: mt_ekko.&lt;BR /&gt;    mo_sql_env-&amp;gt;clear_doubles( ).&lt;BR /&gt;  ENDMETHOD.&lt;BR /&gt;&lt;BR /&gt;  "Test method&lt;BR /&gt;  METHOD test_insert.&lt;BR /&gt;&lt;BR /&gt;    DATA ls_ekko TYPE ekko.&lt;BR /&gt;    ls_ekko = VALUE #( mandt = sy-mandt ebeln = '1234567890' bstyp = 'F' bsart = 'NB' aedat = '20230101' ernam = 'FromInsert' ).&lt;BR /&gt;    INSERT INTO ekko VALUES ls_ekko.&lt;BR /&gt;    cl_abap_unit_assert=&amp;gt;assert_subrc( ).&lt;BR /&gt;&lt;BR /&gt;    READ TABLE mt_ekko INTO DATA(ls_test) INDEX 2.&lt;BR /&gt;    cl_abap_unit_assert=&amp;gt;assert_subrc( msg = 'MT_EKKO doesn''t have a second line.' ). "Test failed here&lt;BR /&gt;&lt;BR /&gt;    cl_abap_unit_assert=&amp;gt;assert_equals(&lt;BR /&gt;      EXPORTING&lt;BR /&gt;        act = ls_test-ernam&lt;BR /&gt;        exp = 'FromInsert' ).&lt;BR /&gt;&lt;BR /&gt;  ENDMETHOD.&lt;BR /&gt;ENDCLASS.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;A good example of what I'm trying to do (with the MODIFY keyword) is the class LTC_TEST_DML_STMNTS from the package SABP_UNIT_DOUBLE_OSQL_DEMO. The downside of this approach is the code only check sy-subrc, and return the value to test. I will no be able to do that in my tests.&lt;/P&gt;
  &lt;P&gt;BR,&lt;/P&gt;
  &lt;P&gt;Antoine&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 15:31:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745745#M2021410</guid>
      <dc:creator>former_member871985</dc:creator>
      <dc:date>2023-07-31T15:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745746#M2021411</link>
      <description>&lt;P&gt;MANDT missing maybe?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;mt_ekko = VALUE #( ( ebeln = '1234567890' bstyp = 'F' bsart = 'NB' aedat = '20230703' ernam = 'setup_method' ) ).

mo_sql_env-&amp;gt;insert_test_data( mt_ekko ).&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 18:20:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745746#M2021411</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-07-31T18:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745747#M2021412</link>
      <description>&lt;P&gt;I forgot this one thanks. But even with the MANDT, nothing change. The subrc of INSERT still at 0, but the double (mt_ekko) still with only one line (from the setup method) in the debugger.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 07:24:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745747#M2021412</guid>
      <dc:creator>former_member871985</dc:creator>
      <dc:date>2023-08-01T07:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745748#M2021413</link>
      <description>&lt;P&gt;No issue in my ABAP 7.57 system, with this minimal reproducible example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT.
CLASS ltc_main DEFINITION
      FOR TESTING
      DURATION SHORT
      RISK LEVEL HARMLESS.
  PRIVATE SECTION.
    METHODS test FOR TESTING.
    CLASS-DATA mo_sql_env     TYPE REF TO if_osql_test_environment.
    DATA mt_ekko TYPE STANDARD TABLE OF ekko.
    CLASS-METHODS class_setup.
    CLASS-METHODS class_teardown.
    METHODS setup.
ENDCLASS.
CLASS ltc_main IMPLEMENTATION.
  METHOD class_setup.
    mo_sql_env = cl_osql_test_environment=&amp;gt;create( i_dependency_list = VALUE #( ( 'EKKO' ) ) ).
  ENDMETHOD.
  METHOD setup.
    mt_ekko = VALUE #( ( ebeln = '1234567890' ) ).
    mo_sql_env-&amp;gt;clear_doubles( ).
    mo_sql_env-&amp;gt;insert_test_data( mt_ekko ).
  ENDMETHOD.
  METHOD test.
    DATA: ls_ekko TYPE ekko.
    ls_ekko-mandt = sy-mandt.
    ls_ekko-ebeln = '1234567890'.
    sy-subrc = 0.
    INSERT INTO ekko VALUES ls_ekko.
    cl_abap_unit_assert=&amp;gt;assert_subrc( exp = 4 ).
  ENDMETHOD.
  METHOD class_teardown.
    mo_sql_env-&amp;gt;destroy( ).
  ENDMETHOD.
ENDCLASS.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Aug 2023 12:50:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745748#M2021413</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-08-01T12:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745749#M2021414</link>
      <description>&lt;P&gt;Thanks for your time and sorry for not being clear. &lt;/P&gt;&lt;P&gt;My insert test is also correct (the sy-subrc returned is 0 because no data exist with the same key) but the row newly inserted isn't in my internal table mt_ekko. As I'm trying to read a second line, this is where I got an error: on my READ TABLE INDEX 2.&lt;/P&gt;&lt;P&gt;My goal is to check my new values in the mt_ekko table to test in the future BAPI custom enhancement.&lt;/P&gt;&lt;P&gt;A good example of what I'm trying to do (with the MODIFY keyword) is the class LTC_TEST_DML_STMNTS
from the package SABP_UNIT_DOUBLE_OSQL_DEMO.  The code test if the price modification is correct. The problem, this test only checks the return price based on the MODIFY subrc :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;" CUT
METHOD change_price.&lt;BR /&gt;  DATA wa TYPE sflight.&lt;BR /&gt;&lt;BR /&gt;  SELECT SINGLE *&lt;BR /&gt;         FROM sflight&lt;BR /&gt;         INTO wa&lt;BR /&gt;         WHERE carrid = carrid AND&lt;BR /&gt;               connid = connid AND&lt;BR /&gt;               fldate = fldate.&lt;BR /&gt;&lt;BR /&gt;  IF sy-subrc &amp;lt;&amp;gt; 0.&lt;BR /&gt;    new_price = - 1.&lt;BR /&gt;    RETURN.&lt;BR /&gt;  ENDIF.&lt;BR /&gt;  wa-price = wa-price * factor / 100.&lt;BR /&gt;&lt;BR /&gt;  MODIFY sflight FROM wa.&lt;BR /&gt;&lt;BR /&gt;  IF sy-subrc = 0.&lt;BR /&gt;    new_price = wa-price.&lt;BR /&gt;  ELSE.&lt;BR /&gt;    new_price = - 2.&lt;BR /&gt;  ENDIF.&lt;BR /&gt;ENDMETHOD.
" End CUT


" Test method (check the 10% discount has been made)
NEW cl_osql_dml_statements( )-&amp;gt;change_price(&lt;BR /&gt;    EXPORTING&lt;BR /&gt;       carrid = 'ZZ'&lt;BR /&gt;       connid = '1234'&lt;BR /&gt;       fldate = sy-datum&lt;BR /&gt;       factor = 90&lt;BR /&gt;     IMPORTING new_price = DATA(new_price) ).&lt;BR /&gt;&lt;BR /&gt;  cl_aunit_assert=&amp;gt;assert_equals(&lt;BR /&gt;   EXPORTING&lt;BR /&gt;     exp = exp          " Called with : invoke_and_assert( 360 )&lt;BR /&gt;     act = new_price  ).
"End test method&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Where the modification takes place? As it's not visible on the double internal table, neither in the DB ... How to validate modified values?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 13:56:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745749#M2021414</guid>
      <dc:creator>former_member871985</dc:creator>
      <dc:date>2023-08-01T13:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745750#M2021415</link>
      <description>&lt;P&gt;What "double internal table" are you talking about? The concept of ABAP SQL Test Double is only in database.&lt;/P&gt;&lt;P&gt;Can't you ask a question with minimal reproducible code that we can copy and paste? (the same as I did)&lt;/P&gt;&lt;P&gt;Otherwise people will stop looking at your question if you give the important information only in the comments.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 14:45:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745750#M2021415</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-08-01T14:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745751#M2021416</link>
      <description>&lt;P&gt;&lt;EM&gt;What "double internal table" are you talking about?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;To what I understood, my MT_EKKO internal table replace the EKKO table while executing unit tests.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Can't you ask a question with minimal reproducible code that we can copy and paste?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I have rewritten my question to me clearer. I hope it's better.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 14:00:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745751#M2021416</guid>
      <dc:creator>former_member871985</dc:creator>
      <dc:date>2023-08-03T14:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745752#M2021417</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;To what I understood, my MT_EKKO internal table replace the EKKO table while executing unit tests.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Wrong. The database table is duplicated in the database under another name and is used instead of EKKO (NB: I'm not expert, I don't know what is exactly behind the scene).&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 14:40:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745752#M2021417</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-08-03T14:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745753#M2021418</link>
      <description>&lt;P&gt;I misunderstood how the ABAP SQL Double Framework works...&lt;/P&gt;&lt;P&gt;As shown &lt;A href="https://help.sap.com/docs/ABAP_PLATFORM_NEW/c238d694b825421f940829321ffa326a/1432ca1fc7b547d493f691cdd09245ae.html?locale=en-US#write-access" target="_blank"&gt;here&lt;/A&gt;, and as &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt; pointed out the framework create a temporary database rather than modifying the internal table given in the setup method (MT_EKKO in my example). &lt;/P&gt;&lt;P&gt;So, in order to read and check modified values, you have to make another select in the test method to assert modifications.&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"Test method&lt;BR /&gt;METHOD test_insert.&lt;BR /&gt;&lt;BR /&gt;  DATA ls_ekko TYPE ekko.&lt;BR /&gt;  ls_ekko = VALUE #( mandt = sy-mandt ebeln = '1234567890' bstyp = 'F' bsart = 'NB' aedat = '20230101' ernam = 'FromInsert' ).&lt;BR /&gt;  INSERT INTO ekko VALUES ls_ekko.&lt;BR /&gt;  cl_abap_unit_assert=&amp;gt;assert_subrc( ).&lt;BR /&gt;&lt;BR /&gt;  SELECT * FROM EKKO INTO TABLE @DATA(lt_ekko).&lt;BR /&gt;&lt;BR /&gt;  READ TABLE lt_ekko INTO DATA(ls_test) INDEX 2.&lt;BR /&gt;  cl_abap_unit_assert=&amp;gt;assert_subrc( msg = 'MT_EKKO doesn''t have a second line.' ).&lt;BR /&gt;&lt;BR /&gt;  cl_abap_unit_assert=&amp;gt;assert_equals(&lt;BR /&gt;    EXPORTING&lt;BR /&gt;      act = ls_test-ernam&lt;BR /&gt;      exp = 'FromInsert' ).&lt;BR /&gt;&lt;BR /&gt;ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2023 16:03:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745753#M2021418</guid>
      <dc:creator>former_member871985</dc:creator>
      <dc:date>2023-08-03T16:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Unit testing database values after insertion</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745754#M2021419</link>
      <description>&lt;P&gt;I just figured it out what you was saying.&lt;/P&gt;&lt;P&gt;Thanks for your answers and your time. I submit an answer with a minimal explanation on what to do to solve this.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 16:07:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-testing-database-values-after-insertion/m-p/12745754#M2021419</guid>
      <dc:creator>former_member871985</dc:creator>
      <dc:date>2023-08-03T16:07:56Z</dc:date>
    </item>
  </channel>
</rss>

