github.com/kubeshop/testkube@v1.17.23/docs/docs/articles/getting-tests-results.md (about) 1 # Getting Results 2 3 We saw how simple it is to create and run Testkube tests executions. Obtaining test results is also simple. 4 5 ## Getting Test Executions After Test is Executed 6 7 After each run, Testkube informs you that you can get results of a given test execution. 8 9 ```sh 10 kubectl testkube run test api-incluster-test 11 ``` 12 13 ```sh title="Expected output:" 14 Type : postman/collection 15 Name : api-incluster-test 16 Execution ID : 615d6398b046f8fbd3d955d4 17 Execution name: openly-full-bream 18 19 Test queued for execution 20 Use the following command to get test execution details: 21 $ kubectl testkube get execution 615d6398b046f8fbd3d955d4 22 23 Or watch test execution until complete: 24 $ kubectl testkube watch execution 615d6398b046f8fbd3d955d4 25 26 ``` 27 28 `testkube get execution 615d6398b046f8fbd3d955d4` - is for getting string output of test execution, where `615d6398b046f8fbd3d955d4` is the test execution ID. 29 30 ## Change the Output Format of Execution Results 31 32 By default, Testkube returns string output of a particular executor. It can also return JSON or Go-Template based outputs. 33 34 ### JSON Output 35 36 Sometimes you need to parse test results programmatically. To simplify this task, test execution results can be in JSON format. 37 38 ```sh 39 testkube get execution 615d7e1ab046f8fbd3d955d6 -o json 40 ``` 41 42 ```json title="Expected output:" 43 { 44 "id": "615d7e1ab046f8fbd3d955d6", 45 "testName": "api-incluster-test", 46 "testType": "postman/collection", 47 "name": "monthly-sure-finch", 48 "executionResult": { 49 "status": "passed", 50 "startTime": "2021-10-06T10:44:46.338Z", 51 "endTime": "2021-10-06T10:44:46.933Z", 52 "output": "newman\n\nAPI-Health\n\n→ Health\n GET http://testkube-api-server:8088/health [200 OK, 124B, 282ms]\n ✓ Status code is 200\n\n┌─────────────────────────┬────────────────────┬───────────────────┐\n│ │ executed │ failed │\n├─────────────────────────┼────────────────────┼───────────────────┤\n│ iterations │ 1 │ 0 │\n├─────────────────────────┼────────────────────┼───────────────────┤\n│ requests │ 1 │ 0 │\n├─────────────────────────┼────────────────────┼───────────────────┤\n│ test-tests │ 2 │ 0 │\n├─────────────────────────┼────────────────────┼───────────────────┤\n│ prerequest-tests │ 1 │ 0 │\n├─────────────────────────┼────────────────────┼───────────────────┤\n│ assertions │ 1 │ 0 │\n├─────────────────────────┴────────────────────┴───────────────────┤\n│ total run duration: 519ms │\n├──────────────────────────────────────────────────────────────────┤\n│ total data received: 8B (approx) │\n├──────────────────────────────────────────────────────────────────┤\n│ average response time: 282ms [min: 282ms, max: 282ms, s.d.: 0µs] │\n└──────────────────────────────────────────────────────────────────┘\n", 53 "outputType": "text/plain", 54 "steps": [ 55 { 56 "name": "Health", 57 "duration": "282ms", 58 "status": "passed", 59 "assertionResults": [ 60 { "name": "Status code is 200", "status": "passed" } 61 ] 62 } 63 ] 64 } 65 } 66 ``` 67 68 It is quite easy to parse data from test executions with tools like `jq` or in other programmatic ways. 69 70 ### Need Non-standard Output? Go-Template for the Rescue 71 72 If you need non-standard test execution output, you can easily use output `-o go` with the passed `--go-template` template content. 73 74 ```sh 75 testkube get execution 615d7e1ab046f8fbd3d955d6 -ogo --go-template='{{.Name}} {{.Id}} {{.ExecutionResult.Status}}' 76 ``` 77 78 ```sh title="Expected output:" 79 monthly-sure-finch 615d7e1ab046f8fbd3d955d6 success 80 ``` 81 82 ## Getting a List of Test Executions 83 84 <!--- Please watch this video on getting tests results in different formats: 85 86 <iframe width="560" height="315" src="https://www.youtube.com/embed/ukHvS5x7TvM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> ---> 87 88 ### Getting a List of Recent Executions 89 90 We can get a list of current executions with use of the `executions` subcommand: 91 92 ```sh 93 testkube get executions 94 ``` 95 96 ```sh title="Expected output:" 97 TEST | TYPE | NAME | ID | STATUS 98 +---------------------+--------------------+------+--------------------------+---------+ 99 api-incluster-test | postman/collection | | 615d7e1ab046f8fbd3d955d6 | success 100 api-incluster-test | postman/collection | | 615d6398b046f8fbd3d955d4 | success 101 kubeshop-cypress | cypress/project | | 615d5372b046f8fbd3d955d2 | success 102 kubeshop-cypress | cypress/project | | 615d5265b046f8fbd3d955d0 | error 103 cypress-example | cypress/project | | 615d4fe6b046f8fbd3d955ce | error 104 cypress-example | cypress/project | | 615d4556b046f8fbd3d955cc | error 105 ``` 106 107 Now we can use an ID to check the results: 108 109 ```sh 110 testkube get execution 615d5265b046f8fbd3d955d0 111 ``` 112 113 ### Getting a List of Executions in Different Formats 114 115 Terminal mode table data is not always best when processing results in code or shell tests. To simplify this, we have implemented JSON or Go-Template based results when getting results lists. 116 117 #### JSON 118 119 Getting JSON results is quite easy, just pass the `-o json` flag to the command: 120 121 ```sh 122 testkube get executions -o json 123 ``` 124 125 ```json title="Expected output:" 126 { 127 "totals": { 128 "results": 17, 129 "passed": 7, 130 "failed": 10, 131 "queued": 0, 132 "pending": 0 133 }, 134 "results": [ 135 { 136 "id": "615d7e1ab046f8fbd3d955d6", 137 "name": "", 138 "testName": "api-incluster-test", 139 "testType": "postman/collection", 140 "status": "passed", 141 "startTime": "2021-10-06T10:44:46.338Z", 142 "endTime": "2021-10-06T10:44:46.933Z" 143 }, 144 { 145 "id": "615d6398b046f8fbd3d955d4", 146 "name": "", 147 "testName": "api-incluster-test", 148 "testType": "postman/collection", 149 "status": "passed", 150 "startTime": "2021-10-06T08:51:39.834Z", 151 "endTime": "2021-10-06T08:51:40.432Z" 152 }, 153 { 154 "id": "615d5372b046f8fbd3d955d2", 155 "name": "", 156 "testName": "kubeshop-cypress", 157 "testType": "cypress/project", 158 "status": "passed", 159 "startTime": "0001-01-01T00:00:00Z", 160 "endTime": "2021-10-06T07:44:30.025Z" 161 }, 162 { 163 "id": "615d5265b046f8fbd3d955d0", 164 "name": "", 165 "testName": "kubeshop-cypress", 166 "testType": "cypress/project", 167 "status": "failed", 168 "startTime": "0001-01-01T00:00:00Z", 169 "endTime": "2021-10-06T07:40:09.261Z" 170 }, 171 { 172 "id": "615d4fe6b046f8fbd3d955ce", 173 "name": "", 174 "testName": "cypress-example", 175 "testType": "cypress/project", 176 "status": "failed", 177 "startTime": "0001-01-01T00:00:00Z", 178 "endTime": "2021-10-06T07:28:54.579Z" 179 }, 180 { 181 "id": "615d4556b046f8fbd3d955cc", 182 "name": "", 183 "testName": "cypress-example", 184 "testType": "cypress/project", 185 "status": "failed", 186 "startTime": "0001-01-01T00:00:00Z", 187 "endTime": "2021-10-06T06:43:44.1Z" 188 }, 189 { 190 "id": "615d43d3b046f8fbd3d955ca", 191 "name": "", 192 "testName": "cypress-example", 193 "testType": "cypress/project", 194 "status": "failed", 195 "startTime": "0001-01-01T00:00:00Z", 196 "endTime": "2021-10-06T06:37:52.601Z" 197 }, 198 { 199 "id": "6155cd7db046f8fbd3d955c8", 200 "name": "", 201 "testName": "postman-test-7f6qrm", 202 "testType": "postman/collection", 203 "status": "passed", 204 "startTime": "2021-09-30T14:45:20.819Z", 205 "endTime": "2021-09-30T14:45:21.419Z" 206 }, 207 { 208 "id": "6155cd67b046f8fbd3d955c6", 209 "name": "", 210 "testName": "sanity", 211 "testType": "postman/collection", 212 "status": "failed", 213 "startTime": "0001-01-01T00:00:00Z", 214 "endTime": "2021-09-30T14:45:00.135Z" 215 }, 216 { 217 "id": "615322f3f47de75f31ae7a06", 218 "name": "", 219 "testName": "long-1", 220 "testType": "postman/collection", 221 "status": "passed", 222 "startTime": "2021-09-28T14:13:11.293Z", 223 "endTime": "2021-09-28T14:13:45.271Z" 224 }, 225 { 226 "id": "61532298f47de75f31ae7a04", 227 "name": "", 228 "testName": "long-1", 229 "testType": "postman/collection", 230 "status": "passed", 231 "startTime": "2021-09-28T14:11:39.179Z", 232 "endTime": "2021-09-28T14:12:15.202Z" 233 }, 234 { 235 "id": "6151b4b342189df67944968e", 236 "name": "", 237 "testName": "postman-test-7f6qrm", 238 "testType": "postman/collection", 239 "status": "passed", 240 "startTime": "2021-09-27T12:10:31.581Z", 241 "endTime": "2021-09-27T12:10:32.105Z" 242 }, 243 { 244 "id": "6151b49d42189df67944968c", 245 "name": "", 246 "testName": "curl-test", 247 "testType": "curl/test", 248 "status": "failed", 249 "startTime": "0001-01-01T00:00:00Z", 250 "endTime": "2021-09-27T12:10:06.954Z" 251 }, 252 { 253 "id": "6151b41742189df67944968a", 254 "name": "", 255 "testName": "curl-test", 256 "testType": "curl/test", 257 "status": "failed", 258 "startTime": "0001-01-01T00:00:00Z", 259 "endTime": "2021-09-27T12:07:52.893Z" 260 }, 261 { 262 "id": "6151b41342189df679449688", 263 "name": "", 264 "testName": "curl-test", 265 "testType": "curl/test", 266 "status": "failed", 267 "startTime": "0001-01-01T00:00:00Z", 268 "endTime": "2021-09-27T12:07:48.868Z" 269 }, 270 { 271 "id": "6151b40f42189df679449686", 272 "name": "", 273 "testName": "curl-test", 274 "testType": "curl/test", 275 "status": "failed", 276 "startTime": "0001-01-01T00:00:00Z", 277 "endTime": "2021-09-27T12:07:44.89Z" 278 }, 279 { 280 "id": "6151b40b42189df679449684", 281 "name": "", 282 "testName": "curl-test", 283 "testType": "curl/test", 284 "status": "failed", 285 "startTime": "0001-01-01T00:00:00Z", 286 "endTime": "2021-09-27T12:07:41.168Z" 287 } 288 ] 289 } 290 ``` 291 292 #### Go-Template 293 294 To get a list of test execution IDs with their corresponding statuses with go-template: 295 296 ```sh 297 testkube get executions -ogo --go-template '{{.Id}}:{{.Status}} ' 298 ``` 299 300 ```sh title="Expected output" 301 615d7e1ab046f8fbd3d955d6:success 615d6398b046f8fbd3d955d4:success 615d5372b046f8fbd3d955d2:success 615d5265b046f8fbd3d955d0:error 615d4fe6b046f8fbd3d955ce:error 615d4556b046f8fbd3d955cc:error 615d43d3b046f8fbd3d955ca:error 6155cd7db046f8fbd3d955c8:success 6155cd67b046f8fbd3d955c6:error 615322f3f47de75f31ae7a06:success 61532298f47de75f31ae7a04:success 6151b4b342189df67944968e:success 6151b49d42189df67944968c:error 6151b41742189df67944968a:error 6151b41342189df679449688:error 6151b40f42189df679449686:error 6151b40b42189df679449684:error 302 ``` 303 304 ### Getting a List of Executions of a Given Test 305 306 To find the execution of a particular test, pass the test name as a parameter: 307 308 ```sh 309 testkube get executions api-incluster-test 310 ``` 311 312 ```sh title="Expected output:" 313 TEST | TYPE | NAME | ID | STATUS 314 +--------------------+--------------------+------+--------------------------+---------+ 315 api-incluster-test | postman/collection | | 615d6398b046f8fbd3d955d4 | success 316 api-incluster-test | postman/collection | | 615d7e1ab046f8fbd3d955d6 | success 317 ``` 318 319 ### Getting the Test Status of a Given Test from Test CRD 320 321 To get the Test CRD status of a particular test, pass the test name as a parameter: 322 323 ```sh 324 testkube get tests container-test --crd-only 325 ``` 326 327 ```yaml title="Expected output:" 328 apiVersion: tests.testkube.io/v3 329 kind: Test 330 metadata: 331 name: container-test 332 namespace: testkube 333 spec: 334 type: container/test 335 content: 336 type: string 337 data: "" 338 executionRequest: 339 artifactRequest: 340 storageClassName: standard 341 volumeMountPath: /share 342 dirs: 343 - test/files 344 status: 345 latestExecution: 346 id: 63b755cab2a16c73e8cfa1c4 347 number: 1 348 startTime: 2023-01-05T22:57:14Z 349 endTime: 2023-01-05T22:57:28Z 350 status: passed 351 ```