![](https://community.sap.com/html/assets/img_tile-default.png)
* ----- super classes for general definitions ----
class test_data definition for testing abstract.
public section.
"constants: constant1....
"data given_...
"data expected...
methods constructor.
endclass.
class test_data implementation.
method constructor.
" set up general test data
endmethod.
endclass.
class test definition for testing risk level harmless duration short
abstract.
protected section.
"data iut type ref to ...
data testdata type ref to test_data.
" mock up test doubles
"data mocked_...
"methods mockup_...
methods setup_low.
methods test_low.
private section.
endclass.
class test implementation.
method setup_low.
"mocked_... = mockup_...
"iut = ...
endmethod.
method test_low.
"cl_abap_unit_assert=>assert_equals(
" exp = testdata->expected_...
" act = iut->....
"cl_abap_testdouble=>verify_expectations( mocked_get_objects ).
endmethod.
endclass.
* ---- Test case "${test_case}" -----
class test_data_${test_case} definition for testing inheriting from test_data.
public section.
methods constructor.
endclass.
class test_data_${test_case} implementation.
method constructor.
super->constructor( ).
" create specific test data
endmethod.
endclass.
class test_${test_case} definition for testing risk level harmless duration short
inheriting from test
final.
private section.
methods setup.
methods test for testing.
endclass.
class test_${test_case} implementation.
method setup.
testdata = new test_data_${test_case}( ).
setup_low( ).
endmethod.
method test.
test_low( ).
endmethod.
endclass.
class test_data definition for testing.
public section.
constants: emp_nr_1 type pernr_d value '1',
emp_nr_2 type pernr_d value '2',
(...) many further constants...
planning_variant type plvar value '01'.
data given_positions type zif_ca03_hr_get_objects=>positions.
data given_employees type zcl_hr05_salhist_types=>employees.
data given_selections type /iwbep/t_mgw_select_option.
data computed_key_objects type zif_ca03_hr_get_objects=>key_objects.
data expected_employees type zif_hr05_position_reader=>employees.
methods constructor.
endclass.
class test_data implementation.
method constructor.
endmethod.
endclass.
class test_data_unfiltered definition for testing inheriting from test_data.
public section.
methods constructor.
endclass.
class test_data_unfiltered implementation.
method constructor.
super->constructor( ).
given_positions =
value #(
plvar = planning_variant
otype = 'S'
( short = emp_nr_1 objid = pos_nr_1 stext = pos_name_1 )
( short = emp_nr_2 objid = pos_nr_2 stext = pos_name_2 )
( short = emp_nr_3 objid = pos_nr_3 stext = pos_name_3 )
( short = emp_nr_4 objid = pos_nr_4 stext = pos_name_4 ) ).
" and so on....
endmethod.
endclass.
class test_data_filtered implementation.
method constructor.
super->constructor( ).
given_selections =
value #(
( property = 'OrgUnit'
select_options = value #( ( sign = 'I' option = 'EQ' low = '21' ) ) ) ).
given_positions =
value #(
plvar = planning_variant
otype = 'S'
( short = emp_nr_1 objid = pos_nr_1 stext = pos_name_1 )
( short = emp_nr_2 objid = pos_nr_2 stext = pos_name_2 ) ).
" and so on...
endmethod.
endclass
class test definition for testing risk level harmless duration short
abstract.
protected section.
data iut type ref to zif_hr05_position_reader.
data testdata type ref to test_data.
data mocked_get_objects type ref to zif_ca03_hr_get_objects.
data mocked_basic type ref to zif_ca03_hr_basic.
data mocked_reader type ref to zif_hr05_salhist_reader.
methods mockup_get_objects
returning value(result) like mocked_get_objects.
methods mockup_basic
returning value(result) like mocked_basic.
methods mockup_reader
returning value(result) like mocked_reader.
methods setup_low.
methods test_low.
private section.
endclass.
class test implementation.
method setup_low.
mocked_basic = mockup_basic( ).
mocked_reader = mockup_reader( ).
mocked_get_objects = mockup_get_objects( ).
iut = zcl_hr05_position_factory=>get_reader( ).
endmethod.
method mockup_basic.
result ?= cl_abap_testdouble=>create( 'zif_ca03_hr_basic' ).
cl_abap_testdouble=>configure_call( result
)->returning( testdata->planning_variant ).
result->get_active_planning_variant( ).
zcl_ca03_hr_injector=>inject_basic( result ).
endmethod.
"implement the rest of the test double mockups
method test_low.
cl_abap_unit_assert=>assert_equals(
exp = testdata->expected_employees
act = iut->read_employees( value #( ) ) ).
cl_abap_testdouble=>verify_expectations( mocked_get_objects ).
endmethod.
endclass.
class test_unfiltered definition for testing risk level harmless duration short
inheriting from test
final.
private section.
methods setup.
methods test for testing.
endclass.
class test_unfiltered implementation.
method setup.
testdata = new test_data_unfiltered( ).
setup_low( ).
endmethod.
method test.
test_low( ).
endmethod.
endclass.
class test_filtered definition for testing risk level harmless duration short
inheriting from test
final.
private section.
methods setup.
methods test for testing.
endclass.
class test_filtered implementation.
method setup.
testdata = new test_data_filtered( ).
setup_low( ).
endmethod.
method test.
test_low( ).
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 |
---|---|
7 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
2 | |
2 |