Skip to main content

JUnit

JUnit check performs a Unit test, parses the JUnit test reports in a container at a specified path as defined in testResults.

junit.yaml
apiVersion: 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"]
FieldDescriptionScheme
name*

Name of the check, must be unique within the canary

string

spec*

Pod specification

Spec

testResults*

Path to JUnit test results

string

timeout

Timeout in minutes to wait for specified container to finish its job. Defaults to 5

integer

description

Description for the check

string

display

Expression to change the formatting of the display

Expression

icon

Icon for overwriting default icon on the dashboard

Icon

labels

Labels for check

map[string]string

metrics

Metrics to export from

[]Metrics

test

Evaluate whether a check is healthy

Expression

transform

Transform data from a check into multiple individual checks

Expression

Export custom metrics from JUnit results
junit.yaml
apiVersion: 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

  1. Add the skipDelete annotation to the canary to prevent created pods from being deleted.

Test Result Variables

NameDescriptionScheme
suites[]JunitSuite
passedNumber of passing testsint
failedNumber of failed testsint
skippedNUmber of tests that were skippedint
errorNumber of errors produced when running the testsint
durationTotal time in secondsfloat64

Junit Suite

NameDescriptionScheme
namestring
tests[]JunitTest
passedNumber of passing testsint
failedNumber of failed testsint
skippedNUmber of tests that were skippedint
errorNumber of errors produced when running the testsint
durationTotal time in secondsfloat64

Junit Test

NameDescriptionScheme
namestring
classnamean additional descriptor for the hierarchy of the test.string
durationTime in secondsfloat64
statusOne of passed, skipped, failed or errorstring
messageDescription optionally included with a skipped,string
propertiesAdditional info about the testmap[string]string
errorAny errors encountered when running a teststring
stdoutStandard output produced during teststring
stderrStandard error output produced during teststring