ABAP UNIT TEST

Hi ,
I am new to oops concept but i am able to understand.
Now i have to create some Unit test plans in ABAP.We are using SAP Netwever 7.1 and WEB AS 6.0
I tried from SE24 but i couldn't get the correct path.
Can you please explain me: if i have a Z program then where and how to write number of Unit test classes. And how it will integrate to with our actual program/FM/any object
Thanks
Umashankar.

You can create the ABAP Unit class as a local class in your program, FM, or class which will test the functionality of that individual code lines. Once you implement the ABAP Unit, you can then run the Unit Test by main menu > Execute > Unit Test. E.g. from Program, Program > Execute > Unit Test.
Check this previous discussions:
ABAP Unit, how to use
Unit Testing concept
Regards,
Naimesh Patel

Similar Messages

  • ABAP Unit Test Problem

    Here we go again on questions regarding ABAPUnit.  We are trying to use Abap unit within a Class object.  All the examples we have seen have to do with Classes and Methods within a Report program. 
    What we have created:
    Class: ZCL_MAIN
    Type: General Class
    Method:  test_abapunit
    Class: ZCL_MAIN_TEST
    Class type: Abap Unit
    Sub Class of ZCL_MAIN
    Method: Test_abapunit_test 
    We try and run the Abap Unit Test from the Test Class and it says it is complete but does not execute our code.  I know we are doing something wrong but are stumped as to what it is.
    Glenn

    Hi Glenn,
    although Uwe and Klaus actually provided for the relevant information we too faced some difficulties at first understanding 'where' you actually put the test classes. So here are the mechanics:
    Open SE80 or SE24 and implement your class ZCL_MAIN.
    While this class is opened, choose <i>Goto->Class-local types->Local Class Definitions/Types</i> from the menu. An editor for local classes is opened on the right.
    Type in your class definition ZCL_MAIN_TEST like this:
    CLASS lcl_main_test DEFINITION FOR TESTING.
      "#AU Risk_Level Harmless
      PRIVATE SECTION.
        CONSTANTS: some_initial_test_value TYPE i VALUE 5.
        DATA: main_class TYPE REF TO zcl_main.
        METHODS setup     FOR TESTING.
        METHODS teardown  FOR TESTING.
        METHODS check_get_my_int FOR TESTING.
        METHODS check_.. FOR TESTING.
    ENDCLASS.
    This is btw a 'normal' local class, no subclass of cl_abap_unit.. whatsoever.
    Go back (menu <i>Goto->Class Definition</i>).
    Choose <i>Goto->Class-local types->local class implementations</i> from the menu.
    Type in your class implementation for ZCL_MAIN_TEST, i.e. implement especially the setup()-method for the test fixture and the various test-methods.
    Compile/activate your class ZCL_MAIN.
    Run the test by choosing <i>Test->Unit Test</i> from the context menu of the class ZCL_MAIN.
    Hope this helps, regards,
    Sebastian

  • Hi Experts, need an example for abap unit test(ABAP OO)?

    Hi Experts,
    I want to do abap unit test for the developed programs, could anyone please give me an example program of development(a simple is ok, just use it to test)? and an abap unit test example for the program, what I want is to use object oriented abap, thanks in advance!
    Merry Christmas to you all.
    Kind regards
    Dawson

    Hi
    Below documents will give you more information,
    http://help.sap.com/saphelp_nw04/helpdata/en/a2/8a1b602e858645b8aac1559b638ea4/content.htm
    ABAP Testing and Troubleshooting [original link is broken]
    http://bi.offis.de/publicProject/g16cglafhqva.htm
    regards
    Nagaraju

  • Transport of ABAP Unit Test Classes between systems.

    Hi guys
    I have a bit of a dilemma on hands here pertaining to the transport of ABAP Unit test classes. Generally when you create a transport containing classes the transport manager will automatically include all "programs" related to the class like the local type definitions, local implementations and with ABAP Unit the local test classes.
    <b>The question that I have is how would one go about excluding the ABAP Unit test classes in transports to production systems and pre-WAS 6.40 systems that do not support ABAP Unit? Does the transport system automatically manage this for you?</b> Any help ideas regarding this would be greatly appreciated.
    Kind regards
    Ettienne Hugo

    Hello Ettienne
    I have a very similar problem that I have to maintain objects for release 6.20 and 6.40. Since I appreciate ABAP Unit Tests as being very helpful I do not want to miss them even in such a situation.
    My approach is as following:
    - If possible, I try to separate the local classes from the tested object, for example:
    - Report or function group
         - contains an include like <z_include_ft01>
                - Within <i><z_include_ft01></i> I have a single stament <i><z_include_au01></i>
    The actual ABAP Unit Tests are coded in <z_include_au01>. Now if I need to ship the development to a release < 6.40 the only thing I need to do is to comment the single INCLUDE statement in <z_include_ft01>. This manual step cannot be ommitted (however, it would be simple task to define an eCATT doing this). In addition, include <z_include_au01> should not be in the transport request for the development (if it happened the import error would not affect the function of the development because it is no longer linked together).
    Advantage of this approach:
    - I clearly see that my development contains ABAP Unit Tests (use naming conventions for the includes) and
    - I can ship - with little effort - the development to SAP releases not supporting ABAP Unit Testing yet
    Regards
      Uwe

  • Hi Experts, questions about abap unit test(abap oo)?

    Hi Experts,
    I am learning abap unit test, could you please tell me some info about how I can test the performance of some specific code in my program? can abap unit test do this kind of job? and could you please tell me what I can do using abap unit test? and some classic examples are appreciated, thanks in advance!
    Kind regards
    Dawson

    Hi
    Below documents will give you more information,
    http://help.sap.com/saphelp_nw04/helpdata/en/a2/8a1b602e858645b8aac1559b638ea4/content.htm
    ABAP Testing and Troubleshooting [original link is broken]
    http://bi.offis.de/publicProject/g16cglafhqva.htm
    regards
    Nagaraju

  • ABAP unit: test classes part of prod. code

    Hi all,
    I've read <a href="https://weblogs.sdn.sap.com/pub/u/266">Thomas Weiss</a>'s weblog: <a href="/people/thomas.weiss/blog/2004/12/17/a-spotlight-on-abap-unit-part-1 Spotlight on ABAP Unit Part 1</a>.
    I posted a question there, but apparently Thomas can't answer at the moment, and since I'm impatient for getting someone's opinion, I reckon we can discuss that topic here  :^)
    As explained in the <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c1be1003-0701-0010-3795-f87160de6483">NetWeaver Developer’s Guide Using ABAP</a>, the test classes are part of the program under test (PUT):
    <i>In ABAP Unit, test classes are part of the production code of the TU. This avoids problems arising from the test code being separate from the production code:
    - Programs and tests must be kept synchronized.
    - You have to ensure that the test and program code are transported together.
    - External test code only enables black box tests with an outside perspective of the tested program.
    Since the test code is part of the production code, it is easy to keep the unit tests and the
    production code up to date if the latter is changed.
    Although the test code and the production code are transported through the system landscape, ABAP unit tests do not increase the load on the production system. By default, the test code is not compiled in the production system. Therefore, the test code can never be executed in the production system.</i>
    On the other hand, this idea is quite different from what suggested by other unit testing frameworks.
    For instance, the documentation of <a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html">Test::Unit - Ruby Unit Testing Framework</a> reads:
    <i>It‘s handy to collect a bunch of related tests, each test represented by a method, into a common test class that knows how to run them.
    The tests will be in a separate class from the code they‘re testing for a couple of reasons. First of all, it allows your code to stay uncluttered with test code, making it easier to maintain. Second, it allows the tests to be stripped out for deployment, since they‘re really there for you, the developer, and your users don‘t need them. Third, and most importantly, it allows you to set up a common test fixture for your tests to run against.</i>
    Regarding the advantages outlined by NetWeaver Developer’s Guide:
    - Programs and tests might be kept synchronized even if they don't belong to the same unit of code.
    - Moreover, you could assure that the test and program code are transported together by saving them in the same package.
    - And quite frankly, I don't have a thourough understanding of the reason why external tests only allow <i>black box tests with an outside perspective</i>.
    What are your opinions on this?
    Regards, Davide

    Hi,
    when I started unit testing with JUnit I was quite surprised that SAP groups the tests with the production code. But now I actually really like it. It has a few advantages:
    - Good tests serve as an excellent documentation so why not bundling them together.
    - If you want to look at the tests they are easy to find.
    - I write all my class tests as local classes. I found out that it really helps me to focus on writing tests only for the class under test. Sometimes it is quite easy to forget the "unit" and write integration tests again.
    Regarding your question:
    >And quite frankly, I don't have a thourough understanding of the reason why external tests only allow black box tests with an outside perspective.
    Usually I would not use the term black box testing in this context. Maybe you mean that it is easy to access private attributes, methods when you group class and testclass together?
    Normally black box testing means that you cannot look at the implementation of the code under test. So your tests are based on the specifications or if there is not one, on your common sense.
    cheers
    Thomas

  • Creating ABAP Unit Tests for Report Programs

    How can we create ABAP unit test  for report programs.
    Please explain the steps?

    Hi Devendra.
    I would like to suggest some references which are as below:
    [SAP HELP - Complete ABAP unit|http://help.sap.com/saphelp_nw04/helpdata/en/a2/8a1b602e858645b8aac1559b638ea4/frameset.htm]
    [SDN - Reference for ABAP unit testing|about unit testing;
    Hope that's usefull.
    Good Luck & Regards.
    Harsh Dave
    Edited by: Harsh Dave on Jul 14, 2008 2:13 PM
    Edited by: Harsh Dave on Jul 14, 2008 2:20 PM

  • How to count the number of test ABAP Unit test methods

    I need to count the number of test methods of a class.   Has anybody done this before?   For example, if I have a class that has 3 methods and I wrote 6 abap unit test methods for it.   I can count the number of methods using cl_abap_classdescr=>describe_by_name (which gave me 3 from my example) but I could not find the function module to count the number of test methods (which should give me 6 in my example).
    I appreciate your reply.

    This call does thew trick.  I just had to make sure the prog name that I pass has "CP" from the 30th pos for it return the result.   Here is thew subroutine that I use:
    form get_test_method_count using     query_class
                               changing  test_method_count.
      data: l_progname type progname.
      l_progname = query_class.
      l_progname+30 = 'CP'.  "needed so the following method will recognize this as a class
      data: l_result type if_aunit_prog_info_types=>ty_t_testclasses.
      try.
          call method cl_aunit_prog_info=>get_tests_of_program
            exporting
              progname = l_progname
            receiving
              result   = l_result.
          if l_result is not initial.
            data: result_rec like line of l_result.
            loop at l_result into result_rec.
              test_method_count = lines( result_rec-methods ).
            endloop.
          endif.
        catch cx_root.
      endtry.
    endform.

  • ABAP UNIT - Test Driven Development

    Dear ABAPers,
    I hope some of you may have also ventured into this area of Test Driven Development.  I have just started looking into this new and exciting way of development.  My understanding after having gone through the available blogs and some reading material on TDD, is that, we have to religiously embrace Object Oriented programing to actually benefit from TDD methodology.  That raised a big question in my mind, how do we implement this technique when we are coding in the user exits like MV45AFZZ, which is mostly classical ABAP programming?
    Please help me understand the TDD a bit more than I currently do.
    Thanks much,
    SMA.
    <- removed by moderator ->
    Edited by: Neil Gardiner on Sep 29, 2010 10:38 AM

    As Dirk already mentioned TDD is writing test before writing productive code. This approach is not limited to OO practices or unit tests.
    E.g. writing an eCatt script in advance that passes as soon the scenario is working, adheres to TDD practices also..
    Vice versa if one practices unit testing and oo patterns it is no TDD if the tests are written after the productive code.
    Regards
      Klaus

  • Abap unit test debug

    when use unit test,how to start up debug model?

    You can put breakpoints in your unit test methods (or helper methods) the same way you can in regular ABAP. As long as it is being executed in the foreground it should be tripped. I have noticed some quirky behavior about when it allows me to place a breakpoint in the code and when it places the breakpoint on the report statement at the beginning of my program, but it IS possible. I do it frequently.
    Regards,
    Andy

  • Issue in ABAP Unit Test

    Hi,
    I am having an issue in Unit Testing of Function Module. The issue is that Interface parameter of FM is not accessed in subroutine as the parameter goes like a field symbol. I get a dump while try to access the Interface parameter.
    Can anyone please help me out on this.

    * Following is my Unit Test Method
    METHOD get_user_formats.
         DATA lv_format   TYPE char35.
         PERFORM get_user_formats USING '2'.
         READ TABLE user_format INTO lv_format INDEX 1.
         " Expected Result
         cl_aunit_assert=>assert_equals( act = lv_format
                                         exp = 'DATE = MM/DD/YYYY').
       ENDMETHOD.     
    FORM get_user_formats USING datfm TYPE datfm.
       DATA: lv_format   TYPE char35.
       SELECT SINGLE ddtext FROM dd07t INTO lv_format
              WHERE domname = 'XUDATFM' AND
                   ddlanguage =  sy-langu AND domvalue_l = datfm.
       CONCATENATE 'DATE = ' lv_format INTO lv_format SEPARATED BY space.
       APPEND lv_format TO user_format.
       CLEAR lv_format.
    * Comment: user_format is a table in TABLES parameter of FM. It is having single field of type CHAR35
    ENDFORM.                    " get_user_formats
    Please note that I get dump ONLY at the time UNIT TESTING. Otherwise the program is running fine.

  • How to make a Abap Unit Test Suit with many test classes

    Hi,
    Problem space
    we have different packages(embedded) in our project and each package corresponds to a differnt functional layer in the design.
    We want to create abab unit test classes for these different layers.
    say embedded package 1 has 10 unit test classses
          embedded package 1 has 20 unit test classses
    How to grup these classes together so that we can start them frm a test suite.
    Code examples and blogs links will be appreciated.
    regards
    anubhav

    This sounds a bit like Project Administration 101 to me.
    I'm not exactly sure what you are actually trying to do here --but generally if you want to functionally test something you need to start with a business process -
    You need to create scripts which tell the user the data to be entered, the transaction to be used and the outcome.
    With SAP you might need to show screen shots of each stage as well.
    You follow this for each complete business process until you've covered the whole business cycle.
    You complete this say individually for Logistics, Purchasing and Finance and then compare what SAP gives you with what you expected to get.
    For some type of testing CATTS can help but without the business processes any testing is essentially meaningless.
    It is totally pointless trying to design a "generic" test plan until you've got the functional consultants to describe the business processes involved.
    Cheers
    jimbo

  • Mocking framework for ABAP unit tests

    Hi, Is there a mocking framework for ABAP ? Something like easymock or mockito for Java ?
    I searched but cannot find anything...
    thanks !

    Hello,
    Now there is one framework available ;-)
    https://github.com/uweku/mockA
    Regards,
    Uwe

  • Two Questions on ABAP UNIT

    I'm familiar with the technical concept of ABAP Unit testing, using both local or global classes, running sets of Unit Tests using the Code Inspector. However, I'm struggling with two issues:
    a) Technical issue: how can I test a Protected or Private method of a class using ABAP Unit testing? It works if the class to be tested has granted friendship to the unit test class, but is that the way to do this?
    b) conceptual issue on the types of Unit Tests to define: the Unit Test is based on comparing actual results with expected results. But how can I predict a result on a development environment that is constantly changing?
    Thanx in advance
    Ben Meijs

    Hi!
    For having plan vs actual report, first of all you need to define CO versions through ORKE for your operating concern. You also needs to define plan version through KE14. Also you need to assign COPA reciever plan version for integrated planning.
         All your SD condition types need to be assigned to value fields. Also to flow actual values of production orders, CO Orders - it is required to assign PA transfer structure to settlement profile. Settlement profile must allow profitlability segments as settlement recievers and it must be stored in settlement profile. The assignment ensures that variances also flows to COPA. Key figure should also be defined for when assessment is caried out from cost center accounting to COPA. Also your value fields are also to be assigned to Cost component structure in COPA.
           After doing above necessary activity, you may plan for your form of report through KE34. Lines, form and header are specified by means of characteristics or value fields.
    Hope it helps a lot!
    Please revert back for any query.
    Thanks & Regards,
    Taral Patel

  • ABAP Unit, how to use

    Hi,
    I created a small example of testing using ABAP Unit shown below.
    But i get a syntax error in German, i translated to English and this is what i get
    The reference to a test class (marking with FOR TESTING) is only in test classes possible
    How do i resolve this?
    CLASS myclass DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA text TYPE string.
        CLASS-METHODS set_text_to_x.
    ENDCLASS.
    CLASS myclass IMPLEMENTATION.
      METHOD set_text_to_x.
        text = 'U'.
      ENDMETHOD.
    ENDCLASS.
    Test classes
    CLASS mytest DEFINITION FOR TESTING.
      PRIVATE SECTION.
        METHODS mytest FOR TESTING.
    ENDCLASS.
    CLASS mytest IMPLEMENTATION .
      METHOD mytest  .
        myclass=>set_text_to_x( ).
        cl_aunit_assert=>assert_equals( act = myclass=>text
                                        exp = 'X'
                                        msg = 'failed').
      ENDMETHOD.
    ENDCLASS.
    DATA my_ref TYPE REF TO mytest.
    CREATE OBJECT my_ref type mytest.
    call METHOD my_ref->mytest.

    You're almost there. You don't need to create a object reference to your ABAP Unit Test class. To run the ABAP Unit test, you need to do the Program > Test > Unit Test
    CLASS myclass DEFINITION.
    PUBLIC SECTION.
    CLASS-DATA text TYPE string.
    CLASS-METHODS set_text_to_x.
    ENDCLASS.
    CLASS myclass IMPLEMENTATION.
    METHOD set_text_to_x.
    text = 'U'.
    ENDMETHOD.
    ENDCLASS.
    * Test classes
    CLASS mytest DEFINITION FOR TESTING.
    PRIVATE SECTION.
    METHODS mytest FOR TESTING.
    ENDCLASS.
    CLASS mytest IMPLEMENTATION .
    METHOD mytest .
    myclass=>set_text_to_x( ).
    cl_aunit_assert=>assert_equals( act = myclass=>text
    exp = 'X'
    msg = 'failed').
    ENDMETHOD.
    ENDCLASS.
    Check thread Unit Test Problem
    Regards,
    Naimesh Patel

Maybe you are looking for

  • FW disks not on desktop but are mounted, no owner?

    This is a weird problem that I wasn't having yesterday but am having today... I'd appreciate some help and advice. I have 2 external fire wire 400 drives daisy chained together and going into the back of my G4 450 runnining os10.4 They have always mo

  • How can I adjust the toolbar font size in Firefox 10.0.2 using Linux?

    I have very poor vision. I am using NoSquint to enlarge all web sites that I visit, but I do not know how to enlarge the font on the toolbar, bookmarks, BBCN RSS news feed, etc. I have 1920x1080 resolution monitor, but I do not want to change from th

  • I tried disk utilities but nothing

    I am trying to make a vacation video, and when I tried to burn it it always got to the end after several hours and told me that it had errors in the encoding. So I went and made a save as disk image. I have an exra hard ware for the memory cause it i

  • I no longer have toolbars, only a narrow strip that disappears until I pull it down; how do I fix this?

    I was on Facebook last night (6/23/11). I'd gone online about 6:30 and immediately was asked about upgrading to Mozilla 5.0; however, I had crops to harvest before 7, so I clicked "remind me later". I went to Farmville and then Facebook (where I alte

  • Reg : Pass One Component's value to other component's value

    Hi all, I have the following code . Here I want to Pass :Pass One Component's value to other component's value <af:image binding="#{backingBeanScope.backing_OText.i1}" id="i1" source="#{(SkinBean.skinFamily == 'MSIE_D2I3')?'/images/d2i3Logo.gif':'/im