-
Notifications
You must be signed in to change notification settings - Fork 1
Home
You want to change a part of your code while run test cases. So you can test effectively.
In ABAP Release 750 there exists the commands test-seam. For older releases than 750 i write this class. It provides the same function as the commands test-seam and test-injection.
We want to replace the return sy-subrc of an authority-check. Instead of test-seam we write in the productive code.
function sample_booking.
data subrc type syst-subrc.
if ztest_injection=>injection_is_activ( 'test_authority_check' ) = abap_true.
* this is the injection. It runs only at the test case.
subrc = 4.
else.
* this is the original code which runs normally
authority-check 'S_CTS_ADMFCT' id 'CTS_ADMFCT' field 'TABL'.
subrc = sy-subrc.
endif.
* to the booking
endfunction.
Instead of test-injection we switch the injection activ. This we do in our test-class.
class test_authority for testing duration short risk level harmless.
private section.
methods authority_check for testing.
endclass.
class test_authority implementation.
method authority_check.
create object ztest_injection=>self.
ztest_injection=>self->injection_set_activ( 'test_authority_check' ).
call function 'SAMPLE_BOOKING'.
* to your tests
ztest_injection=>self->injection_set_inactiv( 'test_authority_check' ).
endmethod.
endclass.
It's important to switch the test injection off (set inactive). Every test injection can be only set activ one time and it must be set inactive afterwards. If you don't switch off and set the injection activ again, you get the runtime error assertion_failed.
If you run the method ' injection_set_activ' outside of a test class you get the exception cx_program_not_found. The class ztest_injection should only used in abap unit tests with class ... definition for testing. Outside of ABAP OO you can't use it.
i use abapgit to upload the source code. It can be downloaded the same way.