Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  program editing →  Testing and Checking Programs →  ABAP Unit →  Test Seams 

TEST-SEAM

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


TEST-SEAM seam. 
  [statement_block]
END-TEST-SEAM.

Effect

The statement TEST-SEAM introduces a test seam called seam which is closed by END-TEST-SEAM. A test class of the current program can use the statement TEST-INJECTION to replace the statement block statement_block using an injection defined there. If no injection is performed for the test seam, the original code is executed.

Test seams have the following properties:

  • Multiple test seams can be defined in a single compilation unit, but each must have a unique name.
  • The general naming conventions apply to the name seam.
  • Test seams cannot be nested, which means that a test seam cannot contain further test seams.
  • A test seam cannot extend beyond the limits of a statement block, but can contain closed control structures.
  • A test seam can include data declarations. These declarations are not replaced when an injection is performed and remain visible in their context.
  • Test seams can be defined in the global declaration part of a program but not in the declaration part of a class.
  • A test seam can be empty (that is, it does not contain any statements). An injection is inserted instead.
  • Test seams cannot be defined in test classes.


Note

Injections can only be created in test classes that are defined in a test include of the current program. Test includes are currently only possible in class pools and function groups. This means that test seams are only feasible in class pools and function groups.


Example

Here, the class CL_DEMO_TEST_SEAMS is an example of production code. The method CHANGE_PRICE multiplies the price of a flight in the database table SFLIGHT by a factor and (if successful) returns the modified price. If a database access fails, a specific invalid value is returned instead of the price.

Test seams are defined for both database accesses. This makes it possible to run a unit test without accessing real data. See the example for TEST-INJECTION.

METHOD change_price.
  DATA wa TYPE sflight.
  TEST-SEAM selection.
    SELECT SINGLE *
           FROM sflight
           INTO wa
           WHERE carrid = carrid AND
                 connid = connid AND
                 fldate = fldate.
  END-TEST-SEAM.
  IF sy-subrc <> 0.
    new_price = -1.
    RETURN.
  ENDIF.
  wa-price = wa-price * factor / 100.
  TEST-SEAM modification.
    MODIFY sflight FROM wa.
  END-TEST-SEAM.
  IF sy-subrc = 0.
    new_price = wa-price.
  ELSE.
    new_price = -2.
  ENDIF.
ENDMETHOD.

Continue

END-TEST-SEAM