Skip to main content

JUnit

Use a JUnit check to run a Kubernetes pod and ingest JUnit XML reports from 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

artifacts

Specify what files/folders created in the pod need to be archived

[]Artifact

timeout

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

integer

dependsOn

Checks that must complete before this check runs

[]string

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]

markFailOnEmpty

If a transformation or datasource returns empty results, the check should fail

boolean

metrics

Metrics to export from

[]Metrics

namespace

Namespace to insert the check result into when it differs from the canary namespace

string

relationships

Relationships that link check results to components or configs

Relationship

test

Evaluate whether a check is healthy

Expression

transform

Transform data from a check into multiple individual checks

Expression

transformDeleteStrategy

Status to apply to transformed checks when the source check no longer returns them

string

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[]JunitTestSuite
passedNumber of passing testsint
failedNumber of failed testsint
skippedNumber of skipped testsint
errorNumber of errors produced when running the testsint
durationTotal time in secondsfloat64

JUnit Test Suite

NameDescriptionScheme
namestring
tests[]JunitTest
passedNumber of passing testsint
failedNumber of failed testsint
skippedNumber of skipped testsint
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
messageText included with a skipped, failed, or errored test casestring
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

Artifact

FieldDescriptionTypeRequired
pathPath or glob.stringtrue

See artifacts