-
Notifications
You must be signed in to change notification settings - Fork 7
/
zcl_koans_about_abapunit.clas.testclasses.abap
228 lines (171 loc) · 7.22 KB
/
zcl_koans_about_abapunit.clas.testclasses.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
*"* use this source file for your ABAP unit test classes
CLASS lcl_about_abapunit DEFINITION FINAL FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS:
"! We shall contemplate truth by testing reality, via asserts.
assert_true FOR TESTING,
"! Ensure the validity of the reference
assert_bound FOR TESTING,
"! Ensure that character string fits to simple pattern
assert_char_cp FOR TESTING,
"! Ensure that character string does not fit to simple pattern
assert_char_np FOR TESTING,
"! Ensure that data objects have distinct values
assert_differs FOR TESTING,
"! Ensure equality of two data objects
assert_equals FOR TESTING,
"! Ensure approximate consistency of 2 floating point numbers
assert_equals_float FOR TESTING,
"! Ensure that boolean equals ABAP_FALSE
assert_false FOR TESTING,
"! Ensure that data object value is initial
assert_initial FOR TESTING,
"! Ensure invalidity of the reference of a reference variable
assert_not_bound FOR TESTING,
"! Ensure that value of data object is not initial
assert_not_initial FOR TESTING,
"! Ensure that number is in given range
assert_number_between FOR TESTING,
"! Ensure specific value of return code
assert_subrc FOR TESTING,
"! Ensure that data is contained as line within internal table
assert_table_contains FOR TESTING,
"! Ensure that data is not contained as line in internal table
assert_table_not_contains FOR TESTING,
"! Ensure that text matches regular expression
assert_text_matches FOR TESTING,
"! Ensure that a constraint is met by data object
assert_that FOR TESTING.
CONSTANTS:
* default_control_flow TYPE aunit_flowctrl VALUE if_aunit_constants=>class.
default_control_flow TYPE int1 VALUE if_abap_unit_constant=>quit-test.
ENDCLASS.
CLASS lcl_about_abapunit IMPLEMENTATION.
METHOD assert_bound.
DATA: koans_ref TYPE REF TO zcl_koans_about_abapunit.
cl_abap_unit_assert=>assert_bound(
act = koans_ref
msg = |Sometimes you need to make some Objects alive... Just think about the reference|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_char_cp.
cl_abap_unit_assert=>assert_char_cp(
act = |abcd|
exp = || "this should be replaced properly
msg = |Do you really think you match the pattern?|
quit = default_control_flow ) .
ENDMETHOD.
METHOD assert_char_np.
cl_abap_unit_assert=>assert_char_np(
act = ||
exp = || "this should be replaced properly
msg = |Wow, could it be possible that this fails on basis of difference|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_differs.
cl_abap_unit_assert=>assert_differs(
act = ||
exp = || "this should be replaced properly
msg = |Here should something be different...|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_equals.
cl_abap_unit_assert=>assert_equals(
act = 1
exp = || "this should be replaced properly
msg = |It´s easy to identify when values should be equal|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_equals_float.
DATA: float_value TYPE decfloat16 VALUE '1.9'.
cl_abap_unit_assert=>assert_equals_float(
act = float_value
exp = CONV decfloat16( 2 ) "this should be replaced properly
msg = |Nearly same isn´t same!|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_false.
cl_abap_unit_assert=>assert_false(
act = |X| "this should be replaced properly
msg = |Like the prior koan. Ponder if you will, the power of simple assertions when verifying an object's behavior|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_initial.
cl_abap_unit_assert=>assert_initial(
act = |X| "this should be replaced properly
msg = |Hey come on... initial means INITIAL|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_not_bound.
data: koans_ref TYPE REF TO zcl_koans_about_abapunit.
koans_ref = NEW #( ). "Here should something be done
cl_abap_unit_assert=>assert_not_bound(
act = koans_ref
msg = |There are times when something should not be null, and this assertion can prove that|
quit = default_control_flow ) .
ENDMETHOD.
METHOD assert_not_initial.
cl_abap_unit_assert=>assert_not_initial(
act = || "this should be replaced properly
msg = |Hey come on... NOT initial means NOT INITIAL|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_number_between.
cl_abap_unit_assert=>assert_number_between(
lower = 1
upper = 3
number = 4 "this should be replaced properly
msg = |Ok, you´re kidding...Find the number hat is in between the others|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_subrc.
cl_abap_unit_assert=>assert_subrc(
exp = 1
act = sy-subrc "this should be replaced properly
msg = |Yes, I know this assertin could be improved...Just check if sy-subrc contains the necessary value|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_table_contains.
TYPES tyt_integer TYPE STANDARD TABLE OF i WITH NON-UNIQUE KEY table_line.
DATA(dref) = NEW tyt_integer( ( 1 ) ( 2 ) ( 3 ) ).
ASSIGN dref->* TO FIELD-SYMBOL(<itab>).
cl_abap_unit_assert=>assert_table_contains(
line = || "this should be replaced properly
table = <itab>
msg = |The line should contain something that´s in the table|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_table_not_contains.
TYPES tyt_integer TYPE STANDARD TABLE OF i WITH NON-UNIQUE KEY table_line.
DATA(dref) = NEW tyt_integer( ( 1 ) ( 2 ) ( 3 ) ).
ASSIGN dref->* TO FIELD-SYMBOL(<itab>).
cl_abap_unit_assert=>assert_table_not_contains(
line = 3 "this should be replaced properly
table = <itab>
msg = |The line should contain something that´s NOT in the table|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_text_matches.
cl_abap_unit_assert=>assert_text_matches(
pattern = |\\D|
text = |123| "this should be replaced properly
msg = |Welcome to regular expressions... find out what the pattern means|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_that.
DATA(abap_koans_constraint) = NEW lcl_koans_demo_constraint( ).
cl_abap_unit_assert=>assert_that(
act = || "this should be replaced properly
exp = abap_koans_constraint
msg = |Hey just look at the constraint class...then you will figure out the expeted value|
quit = default_control_flow ).
ENDMETHOD.
METHOD assert_true.
cl_abap_unit_assert=>assert_true(
act = || "this should be replaced properly
msg = |The \|\| are an attempt to communicate the need to fill in an answer|
quit = default_control_flow ).
ENDMETHOD.
ENDCLASS.