CLASS lth_unit_tests DEFINITION ABSTRACT.
PROTECTED SECTION.
METHODS assert_complex_entity
IMPORTING
act TYPE REF TO zcl_complex_entity
exp TYPE REF TO zcl_complex_entity.
METHODS create_mock_complex_entity
RETURNING
VALUE(result) TYPE REF TO zcl_complex_entity.
ENDCLASS.
CLASS lth_unit_tests IMPLEMENTATION.
METHOD assert_complex_entity.
cl_abap_unit_assert=>assert_equals( act = act->get_description( )
exp = exp->get_description( ) ).
cl_abap_unit_assert=>assert_equals( act = act->get_start_date( )
exp = exp->get_start_date( ) ).
ENDMETHOD.
METHOD create_mock_complex_entity.
result = zcl_complex_factory=>create_complex_entity(
description = `My test description`
start_date = '20200330' ).
ENDMETHOD.
ENDCLASS.
lth_unit_tests
.setup
method might call a factory to instantiate cut
instead of directly using the NEW
keyword. I rarely use class_setup
, class_teardown
or teardown
so I often end up deleting these three methods from the local test classes.CLASS ltc_unit_tests DEFINITION INHERITING FROM lth_unit_tests FINAL FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA cut TYPE REF TO zif_my_interface.
CLASS-METHODS:
class_setup,
class_teardown.
METHODS:
setup,
teardown,
first_test FOR TESTING.
ENDCLASS.
CLASS ltc_unit_tests IMPLEMENTATION.
METHOD class_setup.
ENDMETHOD.
METHOD setup.
cut = NEW zcl_my_class( ).
ENDMETHOD.
METHOD teardown.
ENDMETHOD.
METHOD class_teardown.
ENDMETHOD.
METHOD first_test.
" given
" when
" then
cl_abap_unit_assert=>fail( msg = 'Implement the first test here' ).
ENDMETHOD.
ENDCLASS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 |