ABAP Unit
ABAP Unit is the xUnit adoption for the ABAP language.[src] ABAP Unit is directly embedded into the ABAP development environment and into the ABAP runtime environment.[src] In ABAP Unit tests are test methods in dedicated test classes.[src] A test class may contain several test methods.[src] The optional methods SETUP() and TEARDOWN() offer the possibility to manage the context of the unit tests.[src] Usually test classes are local classes within the program under tests.[src] The domain code and the test code share this way the same life cycle and are always in sync.[src] The test code can exercise the domain code of the program but not vice versa.[src] This restriction is checked by ABAP runtime system and ensures the pattern "no test code in productive code".[src] Test execution for single programs is possible from within the editors.[src] Newer versions of ABAP Unit (>= SAP_BASIS 7.02) offer an integration with coverage metrics and a report to schedule automatic test execution with mail notification.[src] ABAP Unit offers no feature to define test suites programmatically.[src] Mass runs for entire packages can be executed with the Code Inspector integration only.[src] A mocking framework inspired by the fluent interface of EasyMock is provided with the ABAP class CL_ABAP_TESTDOUBLE.[src] Test seams (since ABAP release 7.50) allow rewriting productive code during unit tests.…[src]
ABAP Unit is the xUnit adoption for the ABAP language.[src] ABAP Unit is directly embedded into the ABAP development environment and into the ABAP runtime environment.[src] In ABAP Unit tests are test methods in dedicated test classes.[src] A test class may contain several test methods.[src] The optional methods SETUP() and TEARDOWN() offer the possibility to manage the context of the unit tests.[src] Usually test classes are local classes within the program under tests.[src] The domain code and the test code share this way the same life cycle and are always in sync.[src] The test code can exercise the domain code of the program but not vice versa.[src] This restriction is checked by ABAP runtime system and ensures the pattern "no test code in productive code".[src] Test execution for single programs is possible from within the editors.[src] Newer versions of ABAP Unit (>= SAP_BASIS 7.02) offer an integration with coverage metrics and a report to schedule automatic test execution with mail notification.[src] ABAP Unit offers no feature to define test suites programmatically.[src] Mass runs for entire packages can be executed with the Code Inspector integration only.[src] A mocking framework inspired by the fluent interface of EasyMock is provided with the ABAP class CL_ABAP_TESTDOUBLE.[src] Test seams (since ABAP release 7.50) allow rewriting productive code during unit tests.[src] This allows, for example, database accesses or RFC calls to be overwritten in unit tests.[src] REPORT z_test_aunit.[src] CLASS lcl_constants DEFINITION CREATE PRIVATE.[src] PUBLIC SECTION.[src] CLASS-METHODS class_constructor.[src] INTERFACES zif_constants.[src] "Public interface with the method GET_CONSTANT CLASS-DATA lo_instance TYPE REF TO lcl_constants READ-ONLY.[src] ENDCLASS.[src] CLASS lcl_constants IMPLEMENTATION.[src] METHOD class_constructor.[src] lo_instance = NEW #( ).[src] ENDMETHOD.[src] METHOD zif_constants~get_constant.[src] CASE iv_name.[src] WHEN `Pi`.[src] rv_value = '3.14'.[src] ENDCASE.[src] ENDMETHOD.[src] ENDCLASS.[src] CLASS: lct_math DEFINITION DEFERRED.[src] CLASS lcl_math DEFINITION FRIENDS lct_math.[src] "Allow access to private attributes for the test class.[src] PUBLIC SECTION.[src] METHODS: constructor, quotient IMPORTING iv_a TYPE i iv_b TYPE i RETURNING VALUE(rv_c) TYPE i RAISING cx_sy_arithmetic_error, area_circle IMPORTING iv_r TYPE i RETURNING VALUE(rv_a) TYPE f.[src] PRIVATE SECTION.[src] DATA mo_constants TYPE REF TO zif_constants.[src] ENDCLASS.[src] CLASS lcl_math IMPLEMENTATION.[src] METHOD constructor.[src] mo_constants = lcl_constants=>lo_instance.[src] ENDMETHOD.[src] METHOD quotient.[src] IF iv_b = 0.[src] RAISE EXCEPTION TYPE cx_sy_zerodivide.[src] ELSE.[src] rv_c = iv_a / iv_b.[src] ENDIF.[src] TEST-SEAM bla.[src] WRITE 'test'.[src] END-TEST-SEAM.[src] ENDMETHOD.[src] METHOD area_circle.[src] rv_a = iv_r ** 2 * mo_constants->get_constant( `Pi` ).[src] ENDMETHOD.[src] ENDCLASS.[src] CLASS lct_math DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.[src] PUBLIC SECTION.[src] METHODS t_quotient_1 FOR TESTING.[src] METHODS t_quotient_2 FOR TESTING.[src] METHODS t_area_circle_1 FOR TESTING.[src] PRIVATE SECTION.[src] METHODS setup.[src] METHODS teardown.[src] CLASS-METHODS class_setup.[src] CLASS-METHODS class_teardown.[src] DATA mo_cut TYPE REF TO lcl_math.[src] "Class under testing ENDCLASS.[src] CLASS lct_math IMPLEMENTATION.[src] METHOD setup.[src] mo_cut = NEW #( ).[src] TEST-INJECTION bla.[src] END-TEST-INJECTION.[src] ENDMETHOD.[src] METHOD t_quotient_1.[src] cl_aunit_assert=>assert_equals( act = mo_cut->quotient( iv_a = 6 iv_b = 3 ) exp = 2 ).[src] ENDMETHOD.[src] METHOD t_quotient_2.[src] TRY.[src] mo_cut->quotient( iv_a = 1 iv_b = 0 ).[src] cl_aunit_assert=>fail( ).[src] CATCH cx_sy_arithmetic_error INTO DATA(lo_error).[src] cl_aunit_assert=>assert_bound( lo_error ).[src] ENDTRY.[src] ENDMETHOD.[src] METHOD t_area_circle_1.[src] DATA(lo_constants_mock) = CAST zif_constants( cl_abap_testdouble=>create( `ZIF_CONSTANTS` ) ).[src] cl_abap_testdouble=>configure_call( lo_constants_mock )->returning( CONV f( '3' ) )->and_expect( )->is_called_once( ).[src] lo_constants_mock->get_constant( `Pi` ).[src] mo_cut->mo_constants = lo_constants_mock.[src] "Overwriting the real dependency with the mock object cl_aunit_assert=>assert_equals( act = mo_cut->area_circle( 2 ) exp = 12 ).[src] cl_abap_testdouble=>verify_expectations( lo_constants_mock ).[src] ENDMETHOD.[src] ENDCLASS.[src]
113 sentences · 113 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"ABAP Unit." encyclopegia.org, 2026, https://encyclopegia.org/wiki/abap-unit. Accessed 27 November 2026.
Chicago
"ABAP Unit." encyclopegia.org. Accessed November 27, 2026. https://encyclopegia.org/wiki/abap-unit.
APA
encyclopegia.org. (2026). ABAP Unit. Retrieved November 27, 2026, from https://encyclopegia.org/wiki/abap-unit
Accessed November 27, 2026 · CC BY-SA 4.0 · citation page · JSON