METHOD call_unit_test.
DATA:
lr_au_factory TYPE REF TO cl_aunit_factory,
lr_au_task TYPE REF TO if_aunit_task,
lr_listener TYPE REF TO cl_crm_soc_aunit_listener,
lv_alert TYPE string,
ls_alert TYPE cl_crm_soc_aunit_listener=>ty_s_alert,
lt_alerts TYPE cl_crm_soc_aunit_listener=>ty_t_alerts,
lc_class_method_sep TYPE string VALUE '->',
lv_class_method_line TYPE string.
DATA:
lv_prog_info TYPE if_aunit_prog_info_types=>ty_s_program,
lv_test_class TYPE if_aunit_prog_info_types=>ty_s_testclass,
lr_test_class_handle TYPE REF TO cl_aunit_test_class.
lv_prog_info = cl_aunit_prog_info=>get_program_info(
obj_name = iv_class_name
obj_type = iv_object_type "'FUGR' " 'CLAS'
skip_class_info = abap_false
allow_commit = abap_true ).
READ TABLE lv_prog_info-testclasses INTO lv_test_class INDEX 1.
lr_test_class_handle = cl_aunit_test_class=>create_by_info_structure(lv_test_class
).
" assembly
CREATE OBJECT lr_listener.
CREATE OBJECT lr_au_factory.
lr_au_task = lr_au_factory->create_task( listener = lr_listener ).
" instrument and execute test task
lr_au_task->add_test_class_handle( lr_test_class_handle ).
lr_au_task->run( ).
" do own custom evaluation
lr_listener->get_result( IMPORTING et_alerts = lt_alerts ).
IF lt_alerts IS NOT INITIAL.
LOOP AT lt_alerts INTO ls_alert .
CONCATENATE 'CLASS: ' ls_alert-class lc_class_method_sep ls_alert-method INTO lv_class_method_line.
CONCATENATE lv_class_method_line ls_alert-title INTO lv_alertSEPARATED BY space.
APPEND lv_alert TO et_alerts.
ENDLOOP.
ENDIF.
ENDMETHOD.