Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle exception in ABAP Units?

former_member710796
Discoverer
0 Kudos
960

Hello,

I am trying to write a unit test to cover all the executable statements for the below method;
  METHOD create_file_id.

TRY.
rv_file_id = cl_system_uuid=>create_uuid_c32_static( ).
CATCH cx_uuid_error INTO DATA(lx_uuid_error).
RAISE EXCEPTION TYPE cx_csc_runtime
EXPORTING
textid = cx_csc_runtime=>fileid_creation_error
previous = lx_uuid_error.
ENDTRY.

ENDMETHOD.

I am unaware on how to handle the executable statements under the catch block.

Thank you in Advance,

Rakesh

1 ACCEPTED SOLUTION

775

Hello rakesh_aithal ,

to be able to do that, you need to replace your static method call:

rv_file_id = cl_system_uuid=>create_uuid_c32_static( ).

Because it is static, you can't mock it. So you want to create an new class/interface "zcl_system_uuid", inside this class you can use the static method call. And now, with the known dependancy injection methods, you can control the code under test and raise the exception for your unit test.

Cheers,

Chris

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos
775

Huh? With TRY CATCH of course.

776

Hello rakesh_aithal ,

to be able to do that, you need to replace your static method call:

rv_file_id = cl_system_uuid=>create_uuid_c32_static( ).

Because it is static, you can't mock it. So you want to create an new class/interface "zcl_system_uuid", inside this class you can use the static method call. And now, with the known dependancy injection methods, you can control the code under test and raise the exception for your unit test.

Cheers,

Chris

Sandra_Rossi
Active Contributor
0 Kudos
775

OK, you mean how to mock UUID creation...