JUnit Test Reports
Learn how to parse, visualize, and track test suites trends inside Jenkins by publishing standardized XML test result files.
What are JUnit Test Reports in Jenkins?
When test suites execute inside automated CI pipelines, raw log file prints are hard to audit for bulk pass/fail validation. Build systems and testing engines generate standardized JUnit XML files detailing metadata like total assertions run, failure details, execution duration, and stack traces.
The Jenkins JUnit Plugin parses these output folders dynamically. It transforms raw structured text data into graphical trend diagrams, test history records, flaky test monitors, and detailed dashboards on the job execution UI.
Key Concepts
JUnit XML Schema
The industry-standard XML document format produced automatically by runtime execution engines (like JUnit, PyTest, or Mocha) to describe build test suite health.
The Test Step Engine
Using the declarative pipeline step junit 'target/surefire-reports/*.xml' to load, consume, and structure verification metrics.
Build Health & Flakiness Tracking
Analyzing history sequences over multiple runs to identify flaky test targets and calculating regression curves across recent commits.
Unstable Build Thresholds
Configuring the engine to downgrade build outputs from 'Success' to 'Unstable' when test failures are registered, preserving subsequent deployment steps.
Practical Jenkins Example
The following declarative pipeline executes a Maven test sequence and guarantees that test reports are compiled using a post execution layer, even if individual test targets fail:
pipeline {
agent any
tools {
jdk 'OpenJDK-17'
maven 'Maven-3.9'
}
stages {
stage('Run Test Suite') {
steps {
echo 'Executing test definitions...'
// If tests fail, the shell command errors out, but post step intercepts results
sh 'mvn clean test'
}
}
}
post {
always {
echo 'Processing test report outputs...'
// Captures XML reports produced by Maven Surefire plugin to build UI dashboards
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml'
}
}
}
Practice Exercise
- Verify that the JUnit Plugin is installed via your Manage Jenkins → Plugins panel.
- Create a new Pipeline job in your directory labeled
junit-report-pipeline. - Paste the declarative script listed above into your pipeline code space.
- Trigger consecutive builds. Navigate to your job landing display to investigate the newly populated Test Result Trend charts and individual failure dashboards.
Summary
You have completed the JUnit Test Reports lesson. Visualizing test health enables teams to confidently secure downstream deployment steps, such as archiving deployment-ready binaries.