ABAP unit

from Wikipedia, the free encyclopedia

ABAP Unit is the xUnit implementation for the ABAP programming language . ABAP Unit is directly integrated into the ABAP language and the SE80 and Eclipse development environments.

The module tests are modeled as special test classes. Such a test class has i. d. Usually one or more test methods and optionally special methods for setting up and dismantling the test environment. The test classes can be contained directly in the program to be tested as local classes. This means that there can never be any deviating versions between the module test and the tested functionality. The language integration ensures a strict separation between productive and test code. In this way, the test classes can execute the productive code, but not the other way around.

It is possible to run the module tests directly from the editors and the repository browser of the SE80 ( Ctrl+ Shift+ F10). In newer versions (> = Netweaver 7.02) there is a special ABAP Unit Browser and a link to the coverage determination. With the help of the Code Inspector tool you can run many module tests at once, e.g. B. all module tests that are contained in programs in a package. In ABAP Unit, there is no way to programmatically combine individual unit tests into test suites . As a workaround, however, selection variants for the program RS_AUCV_RUNNER with different packages, classes, function groups and programs to be tested can be created.

As of ABAP 7.40, the class CL_ABAP_TESTDOUBLE is a mocking framework that is syntactically based on EasyMock . ABAP 7.50 introduces the possibility of partial mocking with Test Seams, in which individual code areas (e.g. the function module calls that were previously not mockable) can be redefined in the unit test.

As of ABAP 7.52, database tables can be mocked using the class CL_OSQL_TEST_ENVIRONMENT . The mocked tables replace the originals in Open SQL statements without changes to the productive coding, so that no productive data is used in the test case.

example

class tc_text_buffer definition final for testing
  duration short
  risk level harmless.

  private section.
    methods:
      set_and_get_text for testing
        raising cx_dynamic_check cx_static_check,
      fail_On_Buffer_Overflow for testing
        raising cx_dynamic_check cx_static_check.        

endclass.


class tc_text_buffer implementation.
  
  method fail_on_buffer_overflow.
    data(buffer) = new zcl_text_buffer( ).
    try.
      do 1000 times.
        buffer->add_text( sy-abcde ).
      enddo.
      cl_Abap_unit_assert=>fail( 'No Buffer Overflow' ).
    catch zcx_Buffer_Overflow ##no_Handler.
    endtry.
    
  endmethod.
      
  
  method set_and_get_text.
    constants: c_hello_world type string value 'Hello World'.

    data(buffer) = new zcl_text_buffer( ).
    buffer->set_text( c_hello_world ).

    cl_abap_unit_assert=>assert_equals(
      exporting act = buffer->get_text( )
                exp = c_hello_world ).

  endmethod.

endclass.

See also

literature

Individual evidence

  1. ABAP Test Double Framework - An Introduction | SAP blogs. Retrieved January 7, 2020 .
  2. ABAP News for Release 7.50 - Test Seams and Test Injections | SAP blogs. Retrieved January 7, 2020 .
  3. SAP Help Portal. Retrieved April 1, 2019 .