Skip to content

Commit 6d02ad1

Browse files
committed
Asserts section moved to separate document
1 parent e70a612 commit 6d02ad1

1 file changed

Lines changed: 1 addition & 319 deletions

File tree

docs/references/testcase-reference.md

Lines changed: 1 addition & 319 deletions
Original file line numberDiff line numberDiff line change
@@ -116,325 +116,7 @@ spec:
116116
actual: $Response
117117
```
118118

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

439121

440122
### `expose`

0 commit comments

Comments
 (0)