vendredi 13 juillet 2018

TEST-INJECTION and TEST-SEAM in ABAP code

I’m trying to use TEST-INJECTION and TEST-SEAM in my code. I have following code:

CLASS lcl_undertest DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS mymethod RETURNING VALUE(r) TYPE string.
ENDCLASS.

CLASS lcl_undertest IMPLEMENTATION.
  METHOD mymethod.
    TEST-SEAM vypis.
      r = 'abc'.
    END-TEST-SEAM.
  ENDMETHOD.
ENDCLASS.

CLASS ltc_testclass DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL.
  PRIVATE SECTION.
    METHODS test_method1 FOR TESTING.
ENDCLASS.

CLASS ltc_testclass IMPLEMENTATION.
  METHOD test_method1.

    TEST-INJECTION vypis.
      r = 'xyz'.
    END-TEST-INJECTION.

    DATA(res) = lcl_undertest=>mymethod( ).
    cl_abap_unit_assert=>assert_equals(
      act   = res
      exp   = 'xyz'
      msg   = 'nespravny text'
    ).

  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
WRITE / lcl_undertest=>mymethod( ) .

For these lines

    TEST-INJECTION vypis.
      r = 'xyz'.
    END-TEST-INJECTION.

these three following errors are indicated:

  1. No injection is expected here.
  2. Field "R" is unknown.
  3. Incorrect nesting: For the statement "END-TEST-INJECTION", there is no open structure introduced by "TEST-INJECTION".

I’ve also tried to copy some example codes from documentation and blogs, but there were same errors returned.

What is the reason of problems?

Aucun commentaire:

Enregistrer un commentaire