SAP INTERFACES PARTIALLY ABAP Statements
Get Example source ABAP code based on a different SAP table
• PARTIALLY IMPLEMENTED INTERFACES
ABAP_SYNTAX
What does it do?
The addition
If an interface method that is not implemented is called during a test, an exception from the class
Latest notes:
The addition is particularly useful when classes that are used as test doubles implement interfaces and not all the methods of these implements are called by the code to be tested. Without this addition, it would be necessary to implement all unnecessary methods without values and assign them the
NON_V5_HINTS
ABAP_HINT_END
ABAP_EXAMPLE_VX5
The class
PUBLIC SECTION.
INTERFACES if_http_server PARTIALLY IMPLEMENTED.
ENDCLASS.
CLASS mock_server IMPLEMENTATION.
ENDCLASS.
CLASS mock_request DEFINITION FOR TESTING FINAL.
PUBLIC SECTION.
INTERFACES if_http_request PARTIALLY IMPLEMENTED.
ENDCLASS.
CLASS mock_request IMPLEMENTATION.
METHOD if_http_request~get_form_field.
value = SWITCH spfli-carrid( name WHEN 'carrid' THEN 'LH'
ELSE space ) ##no_text.
ENDMETHOD.
ENDCLASS.
CLASS mock_response DEFINITION FOR TESTING FINAL.
PUBLIC SECTION.
INTERFACES if_http_response PARTIALLY IMPLEMENTED.
DATA output TYPE string.
ENDCLASS.
CLASS mock_response IMPLEMENTATION.
METHOD if_http_response~set_cdata.
me->output = data.
ENDMETHOD.
ENDCLASS.>
Only the interface methods required for the execution of tests are implemented. The interfaces have numerous other methods. These methods must not be implemented when empty due to the addition
The actual test class looks as follows:
DURATION SHORT
RISK LEVEL HARMLESS
FINAL.
PRIVATE SECTION.
DATA mock_request TYPE REF TO mock_request.
DATA mock_response TYPE REF TO mock_response.
DATA mock_server TYPE REF TO mock_server.
DATA handler TYPE REF TO cl_http_ext_service_demo.
METHODS test_service FOR TESTING.
ENDCLASS.
CLASS test_http_service IMPLEMENTATION.
METHOD test_service.
CREATE OBJECT mock_request.
CREATE OBJECT mock_response.
CREATE OBJECT mock_server.
CREATE OBJECT handler.
mock_server->if_http_server~request = mock_request.
mock_server->if_http_server~response = mock_response.
handler->if_http_extension~handle_request( mock_server ).
IF mock_response->output NS ` < meta name='Output' content='Data'>`.
cl_abap_unit_assert=>fail( msg = `Wrong output data` ).
ENDIF.
ENDMETHOD.
ENDCLASS.>
In the test method, ICF is simulated by directly creating objects of the test doubles. The
ABAP_EXAMPLE_END
Return to menu