ABAP 代码中的 TEST-INJECTION 和 TEST-SEAM [英] TEST-INJECTION and TEST-SEAM in ABAP code

查看:57
本文介绍了ABAP 代码中的 TEST-INJECTION 和 TEST-SEAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的代码中使用 TEST-INJECTIONTEST-SEAM.我有以下代码:

CLASS lcl_undertest 定义.公共部分.类方法 mymethod 返回值(r)类型字符串.完结.类 lcl_undertest 实施.方法我的方法.TEST-SEAM vypis.r = 'abc'.端部测试接缝.结束方法.完结.用于测试风险水平无害持续时间短最终的类 ltc_testclass 定义.私人部门.用于测试的方法 test_method1.完结.类 ltc_testclass 实现.方法 test_method1.测试注射 vypis.r = 'xyz'.末端测试注射.DATA(res) = lcl_undertest=>mymethod().cl_abap_unit_assert=>assert_equals(行为 = 资源exp = 'xyz'msg = 'nespravny 文本').结束方法.完结.开始选择.WRITE/lcl_undertest=>mymethod() .

对于这些行

 测试注入 vypis.r = 'xyz'.末端测试注射.

提示以下三个错误:

<块引用>

  1. 此处预计不会注入.
  2. 字段R"未知.
  3. 不正确的嵌套:对于语句END-TEST-INJECTION",没有TEST-INJECTION"引入的开放结构.

我也尝试从文档和博客中复制一些示例代码,但返回了相同的错误.

出现问题的原因是什么?

解决方案

请参阅有关测试接缝的文档 这里.

<块引用>

注意

注入只能在定义在测试包括当前程序.测试包括目前仅可能在类池和功能组中.这意味着测试接缝仅适用于类池和功能组.

另请注意,它们只存在于 ABAP 7.50 版(感谢 Sandra)

明确地说:文档中提到了类池,这意味着它不能在例如报告.您必须使用在其测试包含中定义的本地测试类来声明一个全局类.

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?

解决方案

Please see the documentation regarding test-seams here.

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.

Also be aware that they only exist since ABAP release 7.50 (thanks to Sandra)

To make it clear: the documentation speaks of class pools, meaning that it won't work in e.g. reports. You'll have to declare a global class with the local test class defined in its test include.

这篇关于ABAP 代码中的 TEST-INJECTION 和 TEST-SEAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆