<?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 Unit Test Help in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059031#M1175760</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to build unit test for function module,From SE80 I create test class .&lt;/P&gt;&lt;P&gt;i want to use the class &lt;STRONG&gt;cl_aunit_assert&lt;/STRONG&gt; and for that i have  question.&lt;/P&gt;&lt;P&gt;In the function i import tables and export table  e.g. import_itab &amp;amp; export_itab.&lt;/P&gt;&lt;P&gt;How i check the data if the data o.k.?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any example will help .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 Jan 2009 20:26:40 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-01-12T20:26:40Z</dc:date>
    <item>
      <title>Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059031#M1175760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to build unit test for function module,From SE80 I create test class .&lt;/P&gt;&lt;P&gt;i want to use the class &lt;STRONG&gt;cl_aunit_assert&lt;/STRONG&gt; and for that i have  question.&lt;/P&gt;&lt;P&gt;In the function i import tables and export table  e.g. import_itab &amp;amp; export_itab.&lt;/P&gt;&lt;P&gt;How i check the data if the data o.k.?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any example will help .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 20:26:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059031#M1175760</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-12T20:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059032#M1175761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you search on sdn ??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Search for "cl_aunit_assert"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will find many introductions, wikis, etc., which will explain you what is "abap unit" for, and how it works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 20:58:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059032#M1175761</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-12T20:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059033#M1175762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Michael&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below I show you the coding of an ABAP Unit test class that I use for testing class methods.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CLASS abap_unit_testclass DEFINITION DEFERRED.
CLASS zcl_edi_uk_svcs_out_wilkinson DEFINITION LOCAL FRIENDS abap_unit_testclass.
* ----------------------------------------------------------------------
CLASS abap_unit_testclass DEFINITION FOR TESTING  "#AU Duration Short
  "#AU Risk_Level Harmless
.
* ----------------------------------------------------------------------
* ===============
  PUBLIC SECTION.
* ===============

* ==================
  PROTECTED SECTION.
* ==================

* ================
  PRIVATE SECTION.
* ================
    DATA:
      ms_interval     TYPE nriv,
      md_number       TYPE edi4refint,
      md_next_number  TYPE edi4refint,
      md_flgn         TYPE edi4refint,
      m_ref TYPE REF TO zcl_edi_uk_svcs_out_wilkinson.      "#EC NOTEXT

    METHODS: setup.
    METHODS: teardown.
    METHODS: _constructor_ FOR TESTING.
    METHODS: generate_fgn FOR TESTING.
**    METHODS: map_icn FOR TESTING.
**    METHODS: postprocessing FOR TESTING.
ENDCLASS.       "Abap_Unit_Testclass
* ----------------------------------------------------------------------
CLASS abap_unit_testclass IMPLEMENTATION.
* ----------------------------------------------------------------------

* ----------------------------------------------------------------------
  METHOD setup.
* ----------------------------------------------------------------------

    CREATE OBJECT m_ref.

    " Check existence of number range
    CALL FUNCTION 'NUMBER_GET_INFO'
      EXPORTING
        nr_range_nr              = m_ref-&amp;gt;md_nrnr
        object                   = m_ref-&amp;gt;md_nrobj
*       SUBOBJECT                = ' '
*       TOYEAR                   = '0000'
      IMPORTING
        interval                 = ms_interval
      EXCEPTIONS
        interval_not_found       = 1
        object_not_found         = 2
        OTHERS                   = 3.

    cl_aunit_assert=&amp;gt;assert_subrc(
        exp             = 0
        act             = syst-subrc
        msg             = 'Testing existence of Number Range'
       level            = cl_aunit_assert=&amp;gt;fatal ).


    md_next_number = ms_interval-nrlevel+6(14). " current number (20-digits)
    CALL METHOD zcl_edi_uk_counter=&amp;gt;calculate_modulo_n04
      EXPORTING
        id_input  = md_next_number
      RECEIVING
        rd_output = md_next_number.

    md_flgn = md_next_number+10(4).

  ENDMETHOD.       "Setup

* ----------------------------------------------------------------------
  METHOD teardown.
* ----------------------------------------------------------------------


  ENDMETHOD.       "Teardown


* ----------------------------------------------------------------------
  METHOD _constructor_.
* ----------------------------------------------------------------------

    cl_aunit_assert=&amp;gt;assert_equals(
        exp = 'ZCL_EDI_UK_SVCS_OUT_WILKINSON'
        act = m_ref-&amp;gt;md_clsname
        msg = 'Testing attribute MD_CLSNAME'
        level = cl_aunit_assert=&amp;gt;tolerable ).

    cl_aunit_assert=&amp;gt;assert_equals(
        exp = zcl_edi_uk_counter=&amp;gt;mc_nrobj_fgn
        act = m_ref-&amp;gt;md_nrobj
        msg = 'Testing attribute MD_NROBJ (SNRO Object)'
        level = cl_aunit_assert=&amp;gt;fatal ).

    cl_aunit_assert=&amp;gt;assert_equals(
        exp = zcl_edi_uk_counter=&amp;gt;mc_nrnr_fgn_08_wilkinson
        act = m_ref-&amp;gt;md_nrnr
        msg = 'Testing attribute MD_NRNR (Number Range)'
        level = cl_aunit_assert=&amp;gt;fatal ).

  ENDMETHOD.                    "_constructor_


* ----------------------------------------------------------------------
  METHOD generate_fgn.
* ----------------------------------------------------------------------


    m_ref-&amp;gt;md_flgn = m_ref-&amp;gt;generate_flgn( md_next_number ).

    cl_aunit_assert=&amp;gt;assert_equals(
      act   = m_ref-&amp;gt;md_flgn
      exp   = md_flgn          "&amp;lt;--- please adapt expected value
      msg   = 'Testing File Generation Number (FLGN)'
     level = cl_aunit_assert=&amp;gt;fatal ).

  ENDMETHOD.       "Generate_fgn

ENDCLASS.       "Abap_Unit_Testclass
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the test method you would call your function module with defined input for which you know exactly the expected output.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
METHOD my_test_method.

" Build expected result:
  ... lt_result_expected ....
  

  CALL FUCTION 'Z_MY_FUBA'
    IMPORTING
      ...
    EXPORTING
      ...
    TABLES
      ...  = lt_result.

    cl_aunit_assert=&amp;gt;assert_equals(
      act   = lt_result
      exp   = lt_result_expected          "&amp;lt;--- please adapt expected value
      msg   = 'TABLES parameter of fm'
     level = cl_aunit_assert=&amp;gt;fatal ).

ENDMETHOD.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;   Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 21:36:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059033#M1175762</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-01-12T21:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059034#M1175763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Uwe,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is a table that i expect to get ,for the comparison, i have to fill it hard coded or there another way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Like you write : &lt;U&gt;please adapt expected value.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;cl_aunit_assert=&amp;gt;assert_equals(
      act   = lt_result
      exp   = lt_result_expected          "&amp;lt;--- please adapt expected value
      msg   = 'TABLES parameter of fm'
     level = cl_aunit_assert=&amp;gt;fatal ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2009 08:20:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059034#M1175763</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-13T08:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059035#M1175764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes that's abap unit principle !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2009 08:42:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059035#M1175764</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-13T08:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059036#M1175765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Michael&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can fill the itab with the expected records as you like but the logic MUST BE DIFFERENT from the logic in your fm you want to test. Otherwise you have the trivial case:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;lt_result_expected = lt_result_expected&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...and you will never detect any error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In addition, think of all the possible inputs (right and wrong(!)) for your fm, e.g.&lt;/P&gt;&lt;P&gt;- IMPORTING parameter(s) missing&lt;/P&gt;&lt;P&gt;- IMPORTING parameter(s) having wrong contents (e.g. special characters, etc.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may define for each of this different test cases  a separate test method, e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TEST_FM_INPUT_OK
TEST_FM_MISSING_INPUT
TEST_FM_WRONG_INPUT&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And do not forget to clean up your test environment using method TearDown.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, do not miss out the blog series about ABAP Unit by Thomas Weiss:&lt;/P&gt;&lt;P&gt;&lt;SPAN __jive_macro_name="thread" id="195804"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2009 08:44:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059036#M1175765</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-01-13T08:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059037#M1175766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Uwe ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. From what u say i have to test the input ?,what about the output, i need to declare another 3 methods or more ?&lt;/P&gt;&lt;P&gt;2. I Want to Test FM That have import value like langu (En) and get value in table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2009 08:59:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059037#M1175766</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-13T08:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059038#M1175767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Michael&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Normally you would prepare the initial test data in the &lt;EM&gt;SetUp&lt;/EM&gt; method. However, since you have only a single SetUp method per ABAP Unit class available you would need to create three different test classes which means to break a fly on the wheel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your fm is expected to retrieve language-dependent contents then I would use a single test method where I would vary the input (EN, DE, FR, etc.), get the expected output (e.g. direct SELECT on the DB tables which I usually never no) and use the CL_AUNIT_ASSERT=&amp;gt;ASSERT_EQUALS method to check the output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully your fm raises an exception if the language is unknown (e.g. '?' or 'XY' as input). Here the method of choice would be CL_AUNIT_ASSERT=&amp;gt;ASSERT_SUBRC.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And by the way, do you still use TABLES parameters (hopefully not)? How does the fm behave if the TABLES parameter is already filled (REFRESH at the beginning of the fm, APPEND entries, etc...). Looks like another test case...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2009 09:07:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059038#M1175767</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-01-13T09:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Test Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059039#M1175768</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Uwe,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is MY Fm .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CALL FUNCTION 'Z_GET_ROLE_INF'
        EXPORTING
          iv_language  = 'EN'
        IMPORTING
          et_role_info = role_info
          et_return    = t_return.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;." In t_return i get the error message if language is unknown&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p.s. &lt;/P&gt;&lt;P&gt;instead of fill role_info table for comparison hard coded there is a way to build data container? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2009 11:06:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/unit-test-help/m-p/5059039#M1175768</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-13T11:06:21Z</dc:date>
    </item>
  </channel>
</rss>

