Skip to content

Commit 569062d

Browse files
committed
Assertion documenation
1 parent 2dc5633 commit 569062d

1 file changed

Lines changed: 315 additions & 0 deletions

File tree

docs/05-References/054-testcase-reference.md

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: Testcase specification reference
55
:::note
66
- This page should be use as reference for testcase specification files.
77
- This page is subject to change. It is requested to check this page frequently.
8+
- Currently JSON response is only supported type for assertions.
89
:::
910

1011
The Testcase specification format is how anyone express one or more Testcase/s for a given Http specification. Following is the full reference to write Testcase specification file.
@@ -111,3 +112,317 @@ spec:
111112
- type: assertIsMap
112113
actual: $Response
113114
```
115+
116+
## Assertions
117+
118+
Following are currently supported assertions.
119+
120+
### AssertEqual
121+
122+
Checks if `actual` and `expected` is equal.
123+
124+
```yaml
125+
spec:
126+
...
127+
asserts:
128+
- {type: AssertEqual, actual: $Response.code, expected: 201}
129+
```
130+
131+
### AssertNotEqual
132+
133+
Checks if `actual` and `expected` is not equal.
134+
135+
```yaml
136+
spec:
137+
...
138+
asserts:
139+
- {type: AssertNotEqual, actual: $Response.code, expected: 200}
140+
```
141+
142+
### AssertEmpty
143+
144+
Checks if `actual` is empty.
145+
146+
```yaml
147+
spec:
148+
...
149+
asserts:
150+
- {type: AssertEmpty, actual: $Response.varOne}
151+
```
152+
153+
### AssertFalse
154+
155+
Checks if `actual` is _False_.
156+
157+
```yaml
158+
spec:
159+
...
160+
asserts:
161+
- {type: AssertFalse, actual: $Response.var_2}
162+
```
163+
164+
### AssertTrue
165+
166+
Checks if `actual` is _True_.
167+
168+
```yaml
169+
spec:
170+
...
171+
asserts:
172+
- {type: AssertTrue, actual: $Response.varOne}
173+
```
174+
175+
### AssertIsInt
176+
177+
Checks if `actual` is of type integer.
178+
179+
```yaml
180+
spec:
181+
...
182+
asserts:
183+
- {type: AssertIsInt, actual: $Response.varOne}
184+
```
185+
186+
### AssertIsString
187+
188+
Checks if `actual` is of type string.
189+
190+
```yaml
191+
spec:
192+
...
193+
asserts:
194+
- {type: AssertIsString, actual: $Response.varOne}
195+
```
196+
197+
### AssertIsFloat
198+
199+
Checks if `actual` is of type floating point.
200+
201+
```yaml
202+
spec:
203+
...
204+
asserts:
205+
- {type: AssertIsFloat, actual: $Response.varOne}
206+
```
207+
208+
### AssertIsBool
209+
210+
Checks if `actual` is of type boolean, meaning either _True_ or _False_.
211+
212+
```yaml
213+
spec:
214+
...
215+
asserts:
216+
- {type: AssertIsBool, actual: $Response.varOne}
217+
```
218+
219+
### AssertCount
220+
221+
Checks if `actual` is countable, and have the number of elements given in `expected`. One particular use-case is to test short list of paginated items. Let's say a JSON node `articles` should contains a list of 5 items, then someone would write that as:
222+
223+
```yaml
224+
spec:
225+
...
226+
asserts:
227+
- type: AssertCount
228+
actual: $Response.articles
229+
expected: 5
230+
```
231+
232+
`AssertCount` also can be use to check a JSON object have given number of keys, as well.
233+
234+
### AssertGreater
235+
236+
Checks if `actual` is only greater than `expected` value. Integer, floating point, decimal values can be compared.
237+
238+
```yaml
239+
spec:
240+
...
241+
asserts:
242+
- type: AssertGreater
243+
actual: $Price
244+
expected: 500
245+
```
246+
247+
### AssertGreaterOrEqual
248+
249+
Checks if `actual` is greater than or equal to `expected` value. Integer, floating point, decimal values can be compared.
250+
251+
```yaml
252+
spec:
253+
...
254+
asserts:
255+
- type: AssertGreaterOrEqual
256+
actual: $Price
257+
expected: 500
258+
```
259+
260+
### AssertLess
261+
262+
Checks if `actual` is only less than `expected` value. Integer, floating point, decimal values can be compared.
263+
264+
```yaml
265+
spec:
266+
...
267+
asserts:
268+
- type: AssertLess
269+
actual: $Price
270+
expected: 500
271+
```
272+
273+
### AssertLessOrEqual
274+
275+
Checks if `actual` is less than or equal to `expected` value. Integer, floating point, decimal values can be compared.
276+
277+
```yaml
278+
spec:
279+
...
280+
asserts:
281+
- type: AssertLessOrEqual
282+
actual: $Price
283+
expected: 500
284+
```
285+
286+
### AssertStrContains
287+
288+
Checks if data given in `actual` is a string. If so, does it contains the substring given in `expected`.
289+
290+
```yaml
291+
spec:
292+
...
293+
asserts:
294+
- type: AssertStrContains
295+
actual: "testing is great for code"
296+
expected: 'code'
297+
```
298+
299+
### AssertIsList
300+
301+
Checks if `actual` is of type dictionary. Usually, JSON lists are list.
302+
303+
```yaml
304+
spec:
305+
...
306+
asserts:
307+
- {type: AssertIsList, actual: $Response}
308+
```
309+
310+
### AssertListContains
311+
312+
Checks if data given in `actual` is a list. If so, does it contains the value given in `expected`.
313+
314+
```yaml
315+
spec:
316+
...
317+
asserts:
318+
- type: AssertListContains
319+
actual: $Countries
320+
expected: 'GB'
321+
322+
- type: AssertListContains
323+
actual: $Currency
324+
expected: {"country": "GB", "currency": "GBP"}
325+
```
326+
327+
### AssertListHasIndex
328+
329+
Checks if data given in `actual` is a list. If so, does it contains `expected` index.
330+
331+
```yaml
332+
spec:
333+
...
334+
asserts:
335+
- type: AssertListHasIndex
336+
actual: $Articles
337+
expected: 6
338+
```
339+
340+
### AssertIsMap
341+
342+
Checks if `actual` is of type dictionary. Usually, JSON objects are dictionary.
343+
344+
```yaml
345+
spec:
346+
...
347+
asserts:
348+
- {type: AssertIsMap, actual: $Response}
349+
```
350+
351+
### AssertMapContains
352+
353+
Checks if data given in `actual` is a JSON object or dictionary. If so, does it contains a value given in `expected`.
354+
355+
```yaml
356+
spec:
357+
...
358+
asserts:
359+
- { type: AssertMapContains, actual: $StudentObject, expected: 10 }
360+
```
361+
362+
### AssertMapHasKey
363+
364+
Checks if data given in `actual` is a JSON object or dictionary. If so, does it contains a key given in `expected`.
365+
366+
```yaml
367+
spec:
368+
...
369+
asserts:
370+
- { type: AssertMapHasKey, actual: $StudentObject, expected: 'name' }
371+
```
372+
373+
### AssertMapDoNotHasKey
374+
375+
Checks if data given in `actual` is a JSON object or dictionary. If so, does it DOES NOT contains a key given in `expected`.
376+
377+
```yaml
378+
spec:
379+
...
380+
asserts:
381+
- { type: AssertMapDoNotHasKey, actual: $StudentObject, expected: 'salary' }
382+
```
383+
384+
### AssertMapKeyCount
385+
386+
Checks if data given in `actual` is a JSON object or dictionary. If so, does it have same number of key given in `expected`.
387+
388+
```yaml
389+
spec:
390+
...
391+
asserts:
392+
- { type: AssertMapKeyCount, actual: $StudentObject, expected: 10 }
393+
```
394+
395+
### AssertMapHasKeys
396+
397+
Checks if data given in `actual` is a JSON object or dictionary. If so, does it contains all of keys given in `expected`. `expected` have to be a list of string.
398+
399+
```yaml
400+
spec:
401+
...
402+
asserts:
403+
- { type: AssertMapHasKeys, actual: $StudentObject, expected: ['name', 'section', 'class'] }
404+
```
405+
406+
### AssertMapDoNotHasKeys
407+
408+
Checks if data given in `actual` is a JSON object or dictionary. If so, it DOES NOT contains any of keys given in `expected`. `expected` have to be a list of string.
409+
410+
```yaml
411+
spec:
412+
...
413+
asserts:
414+
- { type: AssertMapDoNotHasKeys, actual: $StudentObject, expected: ['salary', 'year_of_experience'] }
415+
```
416+
417+
### AssertMapExactKeys
418+
419+
Checks if data given in `actual` is a JSON object or dictionary. If so, it only contains keys given in `expected`. `expected` have to be a list of string.
420+
421+
```yaml
422+
spec:
423+
...
424+
asserts:
425+
- type: AssertMapExactKeys
426+
actual: $StudentObject
427+
expected: ['name', 'section', 'class', 'class_teacher_id']
428+
```

0 commit comments

Comments
 (0)