JUnit
JUnit check performs a Unit test, parses the JUnit test reports in a container at a specified path as defined in testResults
.
junit.yamlapiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: junit-pass
spec:
schedule: "@every 2h"
junit:
- testResults: "/tmp/junit-results/"
name: junit-pass
test:
expr: results.failed == 0 && results.passed > 0
display:
expr: "string(results.failed) + ' of ' + string(results.passed)"
spec:
containers:
- name: jes
image: docker.io/tarun18/junit-test-pass
command: ["/start.sh"]
Field | Description | Scheme |
---|---|---|
name* | Name of the check, must be unique within the canary |
|
spec* | Pod specification | |
testResults* | Path to JUnit test results |
|
timeout | Timeout in minutes to wait for specified container to finish its job. Defaults to |
|
description | Description for the check |
|
display | Expression to change the formatting of the display | |
icon | Icon for overwriting default icon on the dashboard | |
labels | Labels for check | map[string]string |
metrics | Metrics to export from | |
test | Evaluate whether a check is healthy | |
transform | Transform data from a check into multiple individual checks |
Export custom metrics from JUnit results
junit.yamlapiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: junit-metrics
labels:
part-of: canary-tools
spec:
schedule: "@every 2h"
severity: high
junit:
- testResults: "/tmp/junit-results/"
name: junit-pass
test:
expr: results.failed == 0 && results.passed > 0
display:
expr: "string(results.failed) + ' of ' + string(results.passed)"
spec:
containers:
- name: jes
image: docker.io/tarun18/junit-test-pass
command: ["/start.sh"]
metrics:
- name: junit_check_pass_count
type: gauge
value: results.passed
labels:
- name: suite_name
valueExpr: results.suites[0].name
- name: junit_check_failed_count
type: gauge
value: results.failed
labels:
- name: part_of
valueExpr: canary.labels['part-of']
- name: junit_check_duration_ms
type: histogram
value: results.duration * 1000.0
labels:
- name: suite_name
valueExpr: results.suites[0].name
Troubleshooting
- Add the
skipDelete
annotation to the canary to prevent created pods from being deleted.
Test Result Variables
Name | Description | Scheme |
---|---|---|
suites | []JunitSuite | |
passed | Number of passing tests | int |
failed | Number of failed tests | int |
skipped | NUmber of tests that were skipped | int |
error | Number of errors produced when running the tests | int |
duration | Total time in seconds | float64 |
Junit Suite
Name | Description | Scheme |
---|---|---|
name | string | |
tests | []JunitTest | |
passed | Number of passing tests | int |
failed | Number of failed tests | int |
skipped | NUmber of tests that were skipped | int |
error | Number of errors produced when running the tests | int |
duration | Total time in seconds | float64 |
Junit Test
Name | Description | Scheme |
---|---|---|
name | string | |
classname | an additional descriptor for the hierarchy of the test. | string |
duration | Time in seconds | float64 |
status | One of passed , skipped , failed or error | string |
message | Description optionally included with a skipped, | string |
properties | Additional info about the test | map[string]string |
error | Any errors encountered when running a test | string |
stdout | Standard output produced during test | string |
stderr | Standard error output produced during test | string |