Test result trends in Jenkins - Time & Space Complexity
We want to understand how the time to analyze test result trends changes as the number of test results grows.
How does the work needed grow when we have more test results to process?
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Analyze Test Results') {
steps {
script {
def results = junit '**/test-results/*.xml'
def trendData = []
for (result in results) {
trendData.add(result.getStatus())
}
}
}
}
}
}
This code collects test results and loops through each to gather status data for trend analysis.
Look for repeated actions in the code.
- Primary operation: Looping through each test result to get its status.
- How many times: Once for every test result found.
As the number of test results increases, the loop runs more times.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 status checks |
| 100 | 100 status checks |
| 1000 | 1000 status checks |
Pattern observation: The work grows directly with the number of test results.
Time Complexity: O(n)
This means the time to analyze test results grows in a straight line as more results come in.
[X] Wrong: "The time to analyze test results stays the same no matter how many results there are."
[OK] Correct: Each test result needs to be checked, so more results mean more work and more time.
Understanding how processing time grows with data size helps you explain efficiency in real projects.
"What if we stored test results in batches and processed only new batches each time? How would the time complexity change?"
Practice
Solution
Step 1: Understand test result trends concept
Test result trends track test outcomes across multiple builds to see progress or issues.Step 2: Identify the main purpose
The main goal is to observe changes in test results over time, helping catch problems early.Final Answer:
To show how test results change over time -> Option AQuick Check:
Test result trends = show changes over time [OK]
- Confusing trends with deployment automation
- Thinking trends create tests
- Assuming trends speed up tests
Solution
Step 1: Identify plugin for JUnit XML reports
JUnit plugin in Jenkins processes JUnit XML test reports and generates test result trends.Step 2: Confirm plugin role
Only the JUnit plugin handles test result publishing and trend visualization from JUnit reports.Final Answer:
JUnit plugin -> Option DQuick Check:
JUnit plugin publishes test trends [OK]
- Choosing Git plugin which manages source code
- Selecting Docker plugin unrelated to tests
- Confusing Pipeline plugin with test reporting
junit '**/test-results.xml' step is missing?pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'run-tests.sh'
junit '**/test-results.xml'
}
}
}
}Solution
Step 1: Understand the role of
Thejunitstepjunitstep publishes test results from XML files and enables trend graphs.Step 2: Analyze missing
Withoutjunitstep effectjunit, test results are not published, so no trends appear, but tests still run.Final Answer:
No test results will be published, no trends available -> Option BQuick Check:
Missing junit step = no published results [OK]
- Thinking pipeline fails without junit step
- Assuming tests won't run without junit
- Believing trends show without publishing results
junit '**/results.xml' step but Jenkins shows no test trends. What is the most likely cause?Solution
Step 1: Check file path pattern for test reports
If the pattern**/results.xmldoes not match any files, no results are published.Step 2: Confirm Jenkins behavior on missing files
Jenkins silently skips publishing if no matching files found, so no trends appear.Final Answer:
The XML file path pattern is incorrect or no files match -> Option AQuick Check:
Wrong file path = no test trends [OK]
- Assuming Jenkins is offline without checking
- Blaming pipeline syntax without error
- Thinking tests must fail to hide trends
junit step to show combined trends?Solution
Step 1: Understand how
Thejunitstep handles multiple filesjunitstep accepts glob patterns to include multiple XML files from different folders.Step 2: Choose best practice for combined trends
Using a singlejunitstep with a combined pattern like'**/test-results/*.xml'publishes all results together, enabling combined trends.Final Answer:
Use a single junit step with a combined glob pattern like '**/test-results/*.xml' -> Option CQuick Check:
Single junit step + combined pattern = combined trends [OK]
- Using multiple junit steps causing separate trends
- Trying to merge XML files manually
- Ignoring some test suites results
Ready to prove it?
Pass the test and this pattern moves unknown
