You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-6Lines changed: 71 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,7 @@ OPTIONS:
65
65
COMMANDS:
66
66
run Run test cases specified in the test file.
67
67
test Run automated testin the test file.
68
+
describe List test cases or describe the contents in a test case.
68
69
69
70
Run 'api-test COMMAND --help'for more information on a command.
70
71
```
@@ -135,6 +136,7 @@ api-test -v -f test.json run test_case_1 # To run in verbose mode use `-v`
135
136
## Automated testing
136
137
137
138
To run an automated test run,
139
+
138
140
```sh
139
141
api-test -f test.json test test_case_1
140
142
api-test -f test.json test all # To run all tests
@@ -359,14 +361,14 @@ To test using `path_eq` check:
359
361
"name":"ram",
360
362
"age":20
361
363
},
362
-
"people[1].name":"Shyam"
364
+
"people[1].name":"Shyam"
363
365
}
364
366
}
365
367
}
366
368
}
367
369
```
368
-
The above example shows how to access an object path to compare and check the values at any depths.
369
370
371
+
The above example shows how to access an object path to compare and check the values at any depths.
370
372
371
373
### 5. path_contains
372
374
@@ -378,10 +380,12 @@ The `path_contains` does the same check as `contains` but allows the check to be
378
380
{
379
381
...
380
382
"expect": {
381
-
"path_contains": {
382
-
"path":"value",
383
-
"path.key1.key":"value"
384
-
}
383
+
"body": {
384
+
"path_contains": {
385
+
"path":"value",
386
+
"path.key1.key":"value"
387
+
}
388
+
}
385
389
}
386
390
}
387
391
@@ -423,6 +427,67 @@ To test using `path_contains` check:
423
427
}
424
428
}
425
429
```
430
+
431
+
### 6. External scripts or program
432
+
433
+
If none of the above checks work for you, there is a way to inject **any language** to compare and test an api response. To do so, provide the command name or script in the `external` key in the `expect` block. If a test case passes return an `exit code 0` and if a test fails `exit code > 0` to communicate with the `api-test` program.
434
+
435
+
#### Syntax
436
+
437
+
```js
438
+
{
439
+
...
440
+
"expect": {
441
+
"body": {...},
442
+
"header": {...},
443
+
"external":"<your program>"
444
+
}
445
+
}
446
+
```
447
+
448
+
Example:
449
+
450
+
test.json
451
+
452
+
```js
453
+
{
454
+
...
455
+
"expect": {
456
+
"body": {...},
457
+
"header": {...},
458
+
"external":"node test.js"
459
+
}
460
+
}
461
+
462
+
```
463
+
464
+
test.js
465
+
466
+
```js
467
+
let testCase =process.argv[2]; // First arg will be test case key
468
+
let body =process.argv[3]; // Second arg will be body
469
+
let header =process.argv[4]; // Third arg will be header
470
+
471
+
let success =true;
472
+
switch (testCase) {
473
+
case"get_api":
474
+
if (success) {
475
+
process.exit(0); // For success case
476
+
} else {
477
+
process.exit(1); // For failure case
478
+
}
479
+
break;
480
+
case"invalid_post_api":
481
+
...
482
+
break;
483
+
484
+
default:
485
+
break;
486
+
}
487
+
```
488
+
489
+
The `test case key`, `body` and `header` are passed respectively to the supplied program. You can use any language as long as you are sending out the correct exit code for failure and success.
490
+
426
491
The above example shows how to access an object path to compare and check the values at any depths. All the above comparison are a subset of response and will pass the check.
0 commit comments