SAP NetWeaver AS ABAP Release 752, ©Copyright 2017 SAP AG. All rights reserved.ABAP - Keyword Documentation → ABAP - Reference → program editing → Testing and Checking Programs → ABAP Unit →
Test seams are language constructs designed especially for unit tests and are implemented using the following statements:
Test seams have the following properties:
Test seams are a simple way of replacing or expanding source code in production parts of a program for test purposes. If, for example, the behavior of certain statements prevents tests from running, the unit test can replace them with suitable alternatives. Typical scenarios are:
Example for authorization checks
An injection can use the statement AUTHORITY-CHECK to bypass the dependency of a unit test on the authorizations of the current user by setting a suitable return code.
AUTHORITY-CHECK OBJECT 'S_CTS_ADMI'
ID 'CTS_ADMFCT' FIELD 'TABL'.
IF sy-subrc = 0.
is_authorized = abap_true.
sy-subrc = 0.
Example for reading persistent data
It is often not possible to make assumptions about the content of database tables or other repositories in unit tests. Using test seams, unit tests can bypass the dependencies of persistent data by replacing it with constructed data.
WHERE carrid IN @carrid_range AND
fldate EQ @sy-datum
INTO TABLE @flights.
VALUE #( ( carrid = 'LHA'
connid = 100 )
( carrid = 'AFR'
connid = 900 ) ).
Example for changing persistent data
When they run, unit tests must not modify production content of database tables or other repositories. Using test seams, unit tests can record the operands of modifying database operations or compare actual changes with expected changes. In the following source code section compares, the injection compares the change values with a public static attribute.
FROM TABLE @new_flights.
act = new_flights
exp = global_buffer=>exp_flights ).
Example for a test double
In the following source code section, the production source text of class that is dependent on database content is instantiated. The unit test injects the instantiated test double at the location of the production object.
me->oref = NEW #( ).
me->oref = NEW dummy_class( ).
See also the class CL_AU_SAMPLE_TEST_SEAMS in the package SABP_UNIT_SAMPLE.