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

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

问题描述

我正在尝试在代码中使用 TEST-INJECTION TEST-SEAM 。我有以下代码:

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( ) .

对于这些行

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

以下三个错误表示:



  1. 此处预计不会注入。

  2. 字段 R未知。

  3. 错误的嵌套:对于 END-TEST-INJECTION语句,没有 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.

也要注意,它们仅存在于ABAP版本7.50(感谢 Sandra

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

To弄清楚:文档中提到了类池,这意味着它在例如报告。您必须使用其测试包含中定义的本地测试类声明一个全局类。

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天全站免登陆