METHOD test_addition.
" given
DATA(input) = `2 + 2`.
" when
DATA(result) = zfh_calculator=>calculate( input ).
" then
cl_abap_unit_assert=>assert_equals( exp = 4 act = result ).
ENDMETHOD.
METHOD test_subtraction.
" given
DATA(input) = `2 - 2`.
" when
DATA(result) = zfh_calculator=>calculate( input ).
" then
cl_abap_unit_assert=>assert_equals( exp = 0 act = result ).
ENDMETHOD.
METHOD test_multiplication.
" given
DATA(input) = `2 * 3`.
" when
DATA(result) = zfh_calculator=>calculate( input ).
" then
cl_abap_unit_assert=>assert_equals( exp = 6 act = result ).
ENDMETHOD.
METHOD test_division.
" given
DATA(input) = `4 / 2`.
" when
DATA(result) = zfh_calculator=>calculate( input ).
" then
cl_abap_unit_assert=>assert_equals( exp = 4 act = result ).
ENDMETHOD.
METHOD test_calculate.
cl_abap_unit_assert=>assert_equals(
act = zfh_calculator=>calculate( `2+2` )
exp = 4 ).
cl_abap_unit_assert=>assert_equals(
act = zfh_calculator=>calculate( `2-2` )
exp = 0 ).
cl_abap_unit_assert=>assert_equals(
act = zfh_calculator=>calculate( `2*3` )
exp = 6 ).
cl_abap_unit_assert=>assert_equals(
act = zfh_calculator=>calculate( `4/2` )
exp = 2 ).
ENDMETHOD.
quit = if_aunit_constants=>quit-no
METHOD test_cases.
TYPES:
BEGIN OF test_case,
input TYPE string,
exp TYPE i,
END OF test_case,
test_cases TYPE HASHED TABLE OF test_case WITH UNIQUE KEY input.
" given
DATA(test) = VALUE test_cases(
( input = `2 + 2` exp = 4 )
( input = `2 - 2` exp = 0 )
( input = `2 * 2` exp = 4 )
( input = `2 / 2` exp = 1 )
).
LOOP AT test ASSIGNING FIELD-SYMBOL(<test_case>).
" when
DATA(result) = f_cut->calculate( <test_case>-input ).
" then
cl_abap_unit_assert=>assert_equals(
exp = <test_case>-exp
act = result
msg = |Failed at { <test_case>-input }. Expected { <test_case>-exp }, received { result }|
quit = if_aunit_constants=>quit-no ).
ENDLOOP.
ENDMETHOD.
METHOD test_cases.
TYPES:
BEGIN OF test_case,
input TYPE string,
exp TYPE string,
END OF test_case,
test_cases TYPE HASHED TABLE OF test_case WITH UNIQUE KEY input.
DATA(test) = VALUE test_cases(
( input = `a` exp = `b` )
).
LOOP AT test ASSIGNING FIELD-SYMBOL(<test_case>).
DATA(result) = f_cut->tested_method( <test_case>-input ).
cl_abap_unit_assert=>assert_equals(
exp = <test_case>-exp
act = result
msg = |Failed at { <test_case>-input }.| &&
|Expected { <test_case>-exp }, received { result }.|
quit = if_aunit_constants=>quit-no ).
ENDLOOP.
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
6 | |
6 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 |