[
{
testDescription: "we do have two distinct target mappings”,
oInput: {
parameter1: "value1",
parameter2: "value2"
oExpected: {
result1: 4711,
result2: {
…
},
{
testDescription: "we do have two equal target mappings",
oInput: {
parameter1: "value21",
parameter2: "value22"
oExpected: {
result1: 1972,
result2: {
…
}
].forEach(function(oFixture) {
asyncTest("getInbound … when " + oFixture.testDescription, function () {
// the actual test code
})
Code Snippet: Fixture coding pattern in Javascript
class ltc_get_inbound definition " Tests method get_inbound of the productive class
for testing
duration short
risk level harmless.
private section.
types:
begin of ts_input,
parameter_1 type string,
parameter_2 type string,
end of ts_input,
begin of ts_expected,
result_1 type i,
result_2 type cl_productive_class=>ts_inbound,
end of ts_expected,
begin of ts_fixture,
description type string,
input type ts_input,
expected type ts_expected,
end of ts_fixture.
methods two_disctint_target_mappings
for testing.
methods two_equal_target_mappings
for testing.
methods test
importing
is_fixture type ts_fixture.
endclass.
class ltc_get_inbound implementation.
method two_disctinct_target_mappings.
data:
ls_fixture type ts_fixture.
" Arrange 1 – create the fixture
ls_fixture = value #(
description = 'we do have two distinct target mappings'
input = value #(
parameter_1 = 'value1'
parameter_2 = 'value2'
)
expected = value #(
result_1 = 4711
result_2 = value #(
...
)
)
).
test( ls_fixture ).
endmethod.
...
method test.
data:
lv_result_1 type string,
ls_result_2 type cl_productive_class=>ts_inbound.
" Arrange 2
data(lo_productive_class) = new cl_productive_class( ).
" I don’t like lo_cut. I prefer a name derived from the actual class name.
" Here I used productive_class wich I would not use in real life code.
" For the example it is okay.
" Act
lo_productive_class->get_inbounds(
exporting
iv_parameter_1 = is_fixture-input-parameter_1
iv_parameter_2 = is_fixture-input-parameter_2
importing
ev_result_1 = lv_result_1
es_result_2 = ls_result_2
).
" Assert
cl_abap_unit=>assert_equals(
exp = is_fixture-expected-result_1
act = lv_result_1
msg = |result_1 is not calculated correctly when { is_fixture-description }|
).
cl_abap_unit=>assert_equals(
exp = is_fixture-expected-result_2
act = lv_result_2
msg = |result_2 is not calculated correctly when { is_fixture-description }|
).
endmethod.
endclass.
* Code Snippet: Fixture coding pattern in ABAP
method two_disctinct_target_mappings.
* begin extraction - marker: cl_productive_class->two_disctinct_target_mappings
* {
* [
* {
* testDescription: "we do have two distinct target mappings”,
* oInput: {
* parameter1: "value1",
* parameter2: "value2"
...
* end extraction - marker: cl_productive_class->two_disctint_target_mappings
data:
lt_test_class_source_code type table of string.
data(lv_method_name) = |{ iv_class_name }->{ iv_method_name }|.
translate iv_class_name to upper case.
translate lv_method_name to lower case.
data(lv_test_class_include) =
cl_oo_classname_service=>get_local_testclasses_include( iv_class_name ).
read report lv_test_class_include into lt_test_class_source_code.
find first occurrence of |begin of json in method { lv_method_name }|
in table lt_test_class_source_code
match line data(lv_begin).
assert sy-subrc = 0.
find first occurrence of |end of json in method { lv_method_name }|
in table lt_test_class_source_code
match line data(lv_end).
assert sy-subrc = 0.
delete it_table from lv_end.
delete it_table from 1 to lv_begin.
loop at it_table assigning field-symbol(<lv_line>).
concatenate rv_json <lv_line>+1 into rv_json.
endloop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |