Skip to content

Commit 8294b45

Browse files
committed
Testcase spec. reference revamp
1 parent 6d02ad1 commit 8294b45

2 files changed

Lines changed: 68 additions & 18 deletions

File tree

docs/references/http-reference.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ request:
302302
```
303303
### `expose`
304304

305-
`expose` is a sub-block, that can be used to expose local variable of this file to outer scope. For specification document that support http request also have a local variable called `$_response` which holds successful response in parsed format.
305+
`expose` is a sub-block, that can be used to expose local variable of this file to outer scope.
306+
307+
For http specification document local variable called `$_response` which holds successful response, is available.
306308

307309
See docs on [expose node](/references/variable-reference#expose-node)

docs/references/testcase-reference.md

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title: Testcase specification reference
88
- Currently JSON response is only supported type for assertions.
99
:::
1010

11-
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.
11+
The _Testcase specification_ format is how anyone express one or more test case(s) for a given _Http specification_. Following is the full reference to write _Testcase specification_ file.
1212

1313
## Testcase specification
1414

@@ -18,14 +18,19 @@ It's also an _**exposable document**_ meaning you can expose local data using `e
1818

1919
### Reference as example
2020

21+
There are 2 ways Testcase doc can be written. 1) `request` is in-file, 2) `request` in separate http file.
22+
23+
#### 1) `request` is in-file
24+
25+
1st way is to write a `request` (that defines the http request) and `spec` (that defines what to assert) in same file. E.g:
26+
2127
```yaml
2228
---
2329
version: 'default:testcase:0.7.2'
2430

2531
variables:
2632
Name: 'Morpheus'
2733
Job: 'leader'
28-
Response: ~
2934
Server: https://reqres.in/api/v1
3035

3136
request:
@@ -35,20 +40,58 @@ request:
3540
'name': $Name,
3641
'job': $Job,
3742
}
38-
return: ~
3943

4044
spec:
41-
execute:
42-
file: ~
43-
with: ~
44-
result: $Response
45-
4645
asserts:
47-
- {type: AssertEqual, actual: $Response.code, expected: 201}
48-
- {type: AssertIsMap, actual: $Response.body}
46+
- {type: AssertEqual, actual: $_response.code, expected: 201}
47+
- {type: AssertIsMap, actual: $_response.body}
4948

5049
expose:
5150
- $_assertion_results
51+
- $_response
52+
```
53+
54+
2) `request` in separate http file
55+
56+
```yaml
57+
# file: some-request.chk
58+
---
59+
version: 'default:testcase:0.7.2'
60+
61+
variables:
62+
Name: 'Morpheus'
63+
Job: 'leader'
64+
Server: https://reqres.in/api/v1
65+
66+
request:
67+
url: "{$Server}/users"
68+
method: POST
69+
body[json]: {
70+
'name': $Name,
71+
'job': $Job,
72+
}
73+
```
74+
75+
and a separate testcase file
76+
77+
```yaml
78+
# file: some-testcase.chk
79+
---
80+
version: 'default:testcase:0.7.2'
81+
82+
spec:
83+
execute:
84+
file: some-request.chk
85+
with:
86+
Name: 'Neo'
87+
Job: 'The chosen one'
88+
89+
asserts:
90+
- {type: AssertEqual, actual: $_response.code, expected: 201}
91+
- {type: AssertIsMap, actual: $_response.body}
92+
93+
expose: ~
94+
5295
```
5396

5497
---
@@ -59,11 +102,13 @@ expose:
59102

60103
### `request`
61104

62-
- _`required`_ if `spec.execute.file` is empty
63-
- _`optional`_ if `spec.execute.file` if a http specification doc is linked
105+
- _`required`_ if no external http spec. doc to be linked
106+
- _`must not`_ if `spec.execute.file` if a http specification doc is linked
64107

65108
`request` is a top-level block that defines a http request. How to write a `request:` block, is [already defined here](/references/http-reference#request-required).
66109

110+
`request` block, and `spec.execute.file` MUST NOT stay on same file. System will throw an error on that case.
111+
67112
### `variables`
68113

69114
`variables` is a top-level block that defines local variables. These variables are file scoped. How to write a `variables:` block, is [already defined here](/references/variable-reference).
@@ -81,8 +126,7 @@ spec:
81126

82127
`spec.execute` is a sub-block that defines a testcase spec's pre-requisite http request execution before making assertion(s). It has following components:
83128

84-
- `spec.execute.file` is used to point the file that contains http specification to run before assertion. If unavailable, or set to null, then execute current file `request` block.
85-
> [TBD] External file not supported now
129+
- `spec.execute.file` is used to point the file that contains http specification to run before assertion. If unavailable, or set to null, then system executes any `request` block from current file.
86130
- `spec.execute.with` is used to pass local scoped variables to external linked file on `spec.execute.file` before execution happen. Not supported for locally linked `request` block.
87131
- `spec.execute.result` is used to store result(s) of the execution. Here we can put a locally scoped variable to receive data to store after request is done.
88132

@@ -93,8 +137,10 @@ variables:
93137
94138
spec:
95139
execute:
96-
file: ~
97-
with: ~
140+
file: some-request.chk
141+
with:
142+
Name: 'Neo'
143+
Job: 'The chosen one'
98144
result: $Response
99145
```
100146

@@ -121,6 +167,8 @@ spec:
121167

122168
### `expose`
123169

124-
`expose` is a sub-block, that can be used to expose local variable of this file to outer scope. For testcase specification document have a local variable called `$_assertion_results` which holds after assertion output.
170+
`expose` is a sub-block, that can be used to expose local variable of this file to outer scope.
171+
172+
For testcase specification document local variable called `$_assertion_results` which holds after assertion output, and `$_response` which holds response after request execute, are available.
125173

126174
See docs on [expose node](/references/variable-reference#expose-node)

0 commit comments

Comments
 (0)