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

Similar Messages

  • 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

  • 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

  • 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

  • Flash Builder 4.6 - How can I keep unit test classes out of the finished swc?

         I have a library of code I'm building and I'm working on unit testing but I have a major issue. When my finished swc compiles no matter what I do it includes the unit test classes as part of the intellisense if you load the swc via flash. The classes aren't really in the swc since if you just try and import them they'll come up undefined. They only appear to go into the intellisense for the swc. Does anyone know how can I keep this from happening in the finished source? Currently my folder setup is like this in flash builder.
    src\main - source documents for the library to get compiled
    src\mock - mock class area for unit testing
    src\test - unit test classes
         In the project Properties panel > the first tab of my Flex Library Build path I have selected only the src\main folder for the classes to inlude in the library. No other folder paths are selected.
    The "Flex Library Build Path" doesn't change my results with any setting.
    Thanks,

    Mel Riffe,
    Here's a Help topic about compiler options in Flash Builder: http://help.adobe.com/en_US/flashbuilder/using/WSe4e4b720da9dedb524b8220812e5611f28f-7fe7. html
    For information on using mxmlc, the application compiler, to compile SWF files from your ActionScript and MXML source files, you can see: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fcc.html
    Hope this helps,
    Mallika Yelandur
    Flash Builder Community Help & Learning
    Adobe Systems Incorporated

  • 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

  • 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

  • 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.

  • 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

  • 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

  • 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.

  • 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

  • ABAP Unit: Can one call a method in the setup/teardown methods?

    Hi all,
    I'm using ABAP Unit test ClasseS (what's with the odd capitalization BTW?) in the class builder on NW7.0.
    In my SETUP method I do not want to do a CREATE OBJECT, but want to use a GET_INSTANCE method of my main class to instantiate my object.
    When I execute my unit test however the instance methods all fail with CX_REF_NOT_ASSIGNED - meaning there is no instance m_ref.
    OK, fair enough methinks, let me debug and see what's going on.
    Surprise: When I set a breakpoint in the SETUP method it all runs fine. Instances are instantiated and instance method tests execute successfully.
    So now I'm a bit stuck trying to investigate a problem that disappears everytime you look at it, a bit like trying to see if the light is off when the fridge is closed... Any ideas?
    Cheers,
    Mike
    Edit: Just to clarify, here's some code:
      method setup.
        m_ref = zcl_myclass=>get_instance( im_key = 'ABC' ).
        " when debugging m_ref is always instantiated and test runs successfully!
      endmethod.       "Setup
      method get_some_data.
        result = m_ref->get_some_data( ).
        " without breakpoint in the setup method, this fails because m_ref is not assigned
      endmethod.
    Edited by: Mike Pokraka on Jun 23, 2008 11:57 PM

    Never mind, found problem, schoolboy error:
    My class_setup method created test data but the update hadn't completed so my GET_INSTANCE failed in normal execution but worked in debug because of the associated delay. 'commit work' needed an 'and wait' and now it's happy.

Maybe you are looking for

  • How to register a jsp page for a function

    Hi, Im new to OA Framework. I have to load a custom jsp page on clicking a function under a responsibility. I logged into "System Administrator" resposibility -->Application --> function. Searched for the function and in the Web HTML set the value as

  • Error while updating SP's for Solman

    Hello , I am updating the SP's for Solman. and I have come across these 3 errors, how do I resolve them 1.Function RSDDTREX_INDEX_CHECK (RSDDTREX_CHECK     01) does not fit into the existing function group ((RSDDTREX     06)) 2.Table RSBGUI_R_TEST is

  • SNC configuration with JCO

    Hi Experts, I am very new to SNC, and my projects requirement is to configure the SNC between the JCO (A java app using JCO api) and ABAP server. JCO(Java application)---ABAP server Is there any docs or writeup/blog which I can refer to achieve this.

  • Iteration non sequencial with While Loop

    I've a SubVi in while Loop. Iteration n+1 will execute when Iteration n finish. Can I execute this SubVi in paralel (no sequencial)? In Spanish: Tengo una SubVi dentro de un bucle while. Pero este bucle actúa de forma secuencial. No se cargará la ite

  • Probleme de batterie i phone 5

    Bonjour, Je suis très déçus de ce téléphone, je suis passé du 4 au 5 dans l'optique d'avoir un produit de meilleur qualité. Or non seulement la batterie ne tien pas et qu'il m a fallut changer de téléphone à l apple store. Mais aujourd hui je me retr