我正在尝试在代码中使用TEST-INJECTION
和TEST-SEAM
。我有以下代码:
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( ) .
对于这些行
TEST-INJECTION vypis.
r = 'xyz'.
END-TEST-INJECTION.
这三个以下错误指示:
- 这里不会注射。
- 字段“ R”未知。
- 不正确的嵌套:对于“ END-TEST-INJECTION”语句,没有“ TEST-INJECTION”引入的开放结构。
我还尝试从文档和博客中复制一些示例代码,但是返回了相同的错误。
出现问题的原因是什么?