1:定义一个辅助类。
CLASS ltd_crms4_techobj_srch_helper DEFINITION FOR TESTING DURATION SHORT INHERITING FROM cl_crms4_techobj_search_helper RISK LEVEL HARMLESS . PUBLIC SECTION. TYPES: BEGIN OF ltys_field_range, fieldname TYPE crmt_fieldname, range TYPE crms4t_range, END OF ltys_field_range, ltyt_field_range TYPE TABLE OF ltys_field_range. DATA mt_field_range TYPE ltyt_field_range . ENDCLASS.
2: 向辅助类中的属性插入值
TEST-INJECTION instance_techobj_srch_helper. data lo_ltd_helper TYPE REF TO ltd_crms4_techobj_srch_helper. create OBJECT lo_ltd_helper. lo_ltd_helper->mt_field_range = VALUE #( ( fieldname = 'RANGE1' range = VALUE #( ( sign = 'I' option = 'CP' low = '*23456789123456789' ) ) ) ( fieldname = 'RANGE2' range = VALUE #( ( sign = 'I' option = 'EQ' low = 'X' ) ) ) ). lo_search_helper = lo_ltd_helper. END-TEST-INJECTION.
因为 lo_search_helper 这时时指向父类的,其属性为私有,因此先创建辅助类实例,给属性赋值,再赋给lo_search_helper
3: 在第一个test injection 中定义过辅助类变量后,其它test-injection 可以直接拿来用。
TEST-INJECTION instance_techobj_srch_helper. * data lo_ltd_helper TYPE REF TO ltd_crms4_techobj_srch_helper. create OBJECT lo_ltd_helper. lo_ltd_helper->mt_field_range = VALUE #( ( fieldname = 'RANGE1' range = VALUE #( ( sign = 'I' option = 'CP' low = '*23456789123456789' ) ) ) ( fieldname = 'RANGE2' range = VALUE #( ( sign = 'I' option = 'EQ' low = 'X' ) ) ) ). lo_search_helper = lo_ltd_helper. END-TEST-INJECTION.