|
| 1 | +--- |
| 2 | +title: Testcase specification reference |
| 3 | +--- |
| 4 | + |
| 5 | +:::note |
| 6 | +- This page should be use as reference for testcase specification files. |
| 7 | +- This page is subject to change. It is requested to check this page frequently. |
| 8 | +::: |
| 9 | + |
| 10 | +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 | + |
| 12 | +## Testcase specification |
| 13 | + |
| 14 | +Testcase specification document is a versioned document, meaning there MUST be a `version:` key on the document. |
| 15 | + |
| 16 | +> [TBD] It's also an exposable document meaning, you can expose local variables to whatever other spec. document it's called from. |
| 17 | +
|
| 18 | +### Reference as example |
| 19 | + |
| 20 | +```yaml |
| 21 | +--- |
| 22 | +version: 'default:testcase:0.7.2' |
| 23 | + |
| 24 | +variables: |
| 25 | + Name: 'Morpheus' |
| 26 | + Job: 'leader' |
| 27 | + Response: ~ |
| 28 | + Server: https://reqres.in/api/v1 |
| 29 | + |
| 30 | +request: |
| 31 | + url: "{$Server}/users" |
| 32 | + method: POST |
| 33 | + body[json]: { |
| 34 | + 'name': $Name, |
| 35 | + 'job': $Job, |
| 36 | + } |
| 37 | + return: ~ |
| 38 | + |
| 39 | +spec: |
| 40 | + execute: |
| 41 | + file: ~ |
| 42 | + with: ~ |
| 43 | + result: $Response |
| 44 | + |
| 45 | + asserts: |
| 46 | + - {type: AssertEqual, actual: $Response.code, expected: 201} |
| 47 | + - {type: AssertIsMap, actual: $Response.body} |
| 48 | +``` |
| 49 | +
|
| 50 | +--- |
| 51 | +
|
| 52 | +### `version` (<small>_`required`_</small>) |
| 53 | + |
| 54 | +`version` is a top-level block that defines a document version. How to write a `version:` block, is [already defined here](/References/version-reference). |
| 55 | + |
| 56 | +### `request` |
| 57 | + |
| 58 | +- _`required`_ if `spec.execute.file` is empty |
| 59 | +- _`optional`_ if `spec.execute.file` if a http specification doc is linked |
| 60 | + |
| 61 | +`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). |
| 62 | + |
| 63 | +### `variables` |
| 64 | + |
| 65 | +`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). |
| 66 | + |
| 67 | +### `spec` (<small>_`required`_</small>) |
| 68 | + |
| 69 | +`spec` is a top-level block that defines a testcase specification. |
| 70 | + |
| 71 | +```yaml |
| 72 | +spec: |
| 73 | + ... |
| 74 | +``` |
| 75 | + |
| 76 | +### `spec.execute` (<small>_`required`_</small>) |
| 77 | + |
| 78 | +`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: |
| 79 | + |
| 80 | +- `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. |
| 81 | + > [TBD] External file not supported now |
| 82 | +- `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. |
| 83 | +- `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. |
| 84 | + |
| 85 | +```yaml |
| 86 | +... |
| 87 | +variables: |
| 88 | + Response: ~ |
| 89 | +
|
| 90 | +spec: |
| 91 | + execute: |
| 92 | + file: ~ |
| 93 | + with: ~ |
| 94 | + result: $Response |
| 95 | +``` |
| 96 | + |
| 97 | +### `spec.assertions` (<small>_`required`_</small>) |
| 98 | + |
| 99 | +`spec.assertions` is a sub-block that defines a testcase spec's post http request execution assertion(s). It supports a list of assertions to be supplied. Each of the list item consists of assertion object. Assertion object have following components: |
| 100 | +{type: AssertEqual, actual: $Response.code, expected: 201} |
| 101 | + |
| 102 | +- `type` of assertion to be executed. |
| 103 | +- `actual` what to assert, usually a local variable or one of it's node. |
| 104 | +- `expected` what is expect value |
| 105 | + |
| 106 | +```yaml |
| 107 | +... |
| 108 | +spec: |
| 109 | + asserts: |
| 110 | + - {type: AssertEqual, actual: $Response.code, expected: 201} |
| 111 | + - type: assertIsMap |
| 112 | + actual: $Response |
| 113 | +``` |
0 commit comments