Bird
Raised Fist0
Jenkinsdevops~20 mins

JUnit test report publishing in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
JUnit Test Report Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of JUnit Test Report Publishing in Jenkins

What is the main purpose of publishing JUnit test reports in Jenkins pipelines?

ATo automatically fix failing tests during the build
BTo display test results and trends in Jenkins UI for easy monitoring
CTo deploy the application after tests pass
DTo generate code coverage reports from test execution
Attempts:
2 left
💡 Hint

Think about what Jenkins shows after tests run.

❓ Predict Output
intermediate
2:00remaining
Output of Jenkins Pipeline with JUnit Step

Given this Jenkins pipeline snippet, what will Jenkins display after running the tests?

Jenkins
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        junit 'target/surefire-reports/*.xml'
      }
    }
  }
}
AJenkins ignores the test reports and continues without output
BJenkins fails the build immediately without showing test results
CJenkins shows a summary of test results including passed, failed, and skipped tests
DJenkins shows code coverage percentage instead of test results
Attempts:
2 left
💡 Hint

What does the junit step do with XML reports?

❓ assertion
advanced
2:00remaining
Correct Assertion for JUnit Test Result in Jenkinsfile

Which assertion correctly fails the Jenkins build if any JUnit test fails?

Jenkins
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        junit 'target/surefire-reports/*.xml'
        // Assertion here
      }
    }
  }
}
Ascript { if (currentBuild.result != 'SUCCESS') error('Tests failed') }
Bscript { assert currentBuild.result == 'SUCCESS' }
Cscript { if (currentBuild.result == 'FAILURE') error('Tests failed') }
Dscript { assert currentBuild.result != 'FAILURE' }
Attempts:
2 left
💡 Hint

Consider how Jenkins sets currentBuild.result after tests.

🔧 Debug
advanced
2:00remaining
Debugging Missing JUnit Test Reports in Jenkins

After running tests, Jenkins shows 'No test reports found'. What is the most likely cause?

AThe Jenkinsfile syntax is invalid causing the step to be skipped
BThe tests did not run because the build agent was offline
CJUnit is not installed on the Jenkins server
DThe path in the <code>junit</code> step does not match the actual location of XML files
Attempts:
2 left
💡 Hint

Check the file path pattern used in the junit step.

❓ framework
expert
3:00remaining
Configuring Jenkins to Archive JUnit Reports and Fail Build on Test Failures

Which Jenkins pipeline snippet correctly archives JUnit test reports and fails the build if any test fails?

A
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        junit 'target/surefire-reports/*.xml'
        script {
          if (currentBuild.result != 'SUCCESS') {
            error('Tests failed')
          }
        }
      }
    }
  }
  post {
    always {
      archiveArtifacts 'target/surefire-reports/*.xml'
    }
  }
}
B
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        junit 'target/surefire-reports/*.xml'
      }
    }
  }
  post {
    always {
      archiveArtifacts 'target/surefire-reports/*.xml'
      script {
        if (currentBuild.result == 'FAILURE') {
          error('Tests failed')
        }
      }
    }
  }
}
C
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        junit 'target/surefire-reports/*.xml'
        archiveArtifacts 'target/surefire-reports/*.xml'
      }
    }
  }
  post {
    failure {
      error('Tests failed')
    }
  }
}
D
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        junit 'target/surefire-reports/*.xml'
      }
    }
  }
  post {
    always {
      archiveArtifacts 'target/surefire-reports/*.xml'
    }
    failure {
      error('Tests failed')
    }
  }
}
Attempts:
2 left
💡 Hint

Consider where to check the build result and where to archive artifacts.

Practice

(1/5)
1. What is the main purpose of publishing JUnit test reports in Jenkins?
easy
A. To run tests faster on Jenkins agents
B. To display test results clearly in Jenkins for easy review
C. To compile Java code before testing
D. To deploy the application automatically after tests

Solution

  1. Step 1: Understand JUnit report publishing

    Publishing JUnit reports in Jenkins helps show test results in a readable format.
  2. Step 2: Identify the main goal

    The main goal is to review test outcomes easily, not to run tests or deploy code.
  3. Final Answer:

    To display test results clearly in Jenkins for easy review -> Option B
  4. Quick Check:

    JUnit reports show test results [OK]
Hint: JUnit reports = test results display in Jenkins [OK]
Common Mistakes:
  • Confusing report publishing with running tests
  • Thinking it compiles code
  • Assuming it triggers deployment
2. Which Jenkins pipeline syntax correctly publishes JUnit test reports stored in target/surefire-reports/*.xml?
easy
A. post { always { junit 'target/surefire-reports/*.xml' } }
B. steps { junit 'target/surefire-reports/*.xml' }
C. post { junit 'target/surefire-reports/*.xml' }
D. publishJUnit 'target/surefire-reports/*.xml'

Solution

  1. Step 1: Identify correct placement of junit step

    The junit step must be inside a post block, usually with always to run after build.
  2. Step 2: Check syntax correctness

    post { always { junit 'target/surefire-reports/*.xml' } } uses post { always { junit 'path' } } which is correct syntax for publishing reports.
  3. Final Answer:

    post { always { junit 'target/surefire-reports/*.xml' } } -> Option A
  4. Quick Check:

    junit inside post always block [OK]
Hint: Put junit step inside post { always { ... } } [OK]
Common Mistakes:
  • Placing junit directly under steps without post
  • Using wrong step name like publishJUnit
  • Omitting the always block inside post
3. Given this Jenkins pipeline snippet, what will happen after the build if the test reports are saved in build/test-results/*.xml?
post {
  always {
    junit 'build/test-results/*.xml'
  }
}
medium
A. JUnit reports will be ignored because path is incorrect
B. Tests will rerun automatically after the build
C. Build will fail if no test reports are found
D. JUnit test results will be published and visible in Jenkins UI

Solution

  1. Step 1: Understand junit step behavior

    The junit step publishes test results from the given XML path after the build.
  2. Step 2: Check the path and effect

    The path build/test-results/*.xml matches where reports are saved, so results will be published and shown.
  3. Final Answer:

    JUnit test results will be published and visible in Jenkins UI -> Option D
  4. Quick Check:

    Correct path + junit step = results published [OK]
Hint: Correct path in junit step shows results in Jenkins [OK]
Common Mistakes:
  • Thinking tests rerun automatically
  • Assuming build fails if reports missing
  • Believing reports are ignored without error
4. You added this to your Jenkinsfile but test reports do not appear in Jenkins UI:
post {
  always {
    junit 'reports/*.xml'
  }
}
What is the most likely cause?
medium
A. The junit step must be inside the steps block, not post
B. The junit step requires a full absolute path
C. The report files are not saved in the 'reports' directory
D. The pipeline must use 'archiveArtifacts' to publish reports

Solution

  1. Step 1: Verify report file location

    If reports are not saved in 'reports/*.xml', junit cannot find them to publish.
  2. Step 2: Understand junit step requirements

    junit works with relative paths and does not require absolute paths or archiveArtifacts for publishing test results.
  3. Final Answer:

    The report files are not saved in the 'reports' directory -> Option C
  4. Quick Check:

    Wrong report path = no results shown [OK]
Hint: Check report file path matches junit pattern [OK]
Common Mistakes:
  • Placing junit outside post block
  • Using absolute paths unnecessarily
  • Confusing junit with archiveArtifacts
5. You want Jenkins to publish JUnit reports only if tests run successfully, but still archive reports even if tests fail. Which Jenkinsfile snippet achieves this?
hard
A. post { success { junit 'test-results/*.xml' } always { archiveArtifacts 'test-results/*.xml' } }
B. post { always { junit 'test-results/*.xml' archiveArtifacts 'test-results/*.xml' } }
C. post { failure { junit 'test-results/*.xml' } success { archiveArtifacts 'test-results/*.xml' } }
D. post { success { archiveArtifacts 'test-results/*.xml' } always { junit 'test-results/*.xml' } }

Solution

  1. Step 1: Understand conditions for junit and archiveArtifacts

    To publish JUnit reports only on success, place junit inside success block. To archive always, place archiveArtifacts inside always.
  2. Step 2: Match snippet to requirements

    post { success { junit 'test-results/*.xml' } always { archiveArtifacts 'test-results/*.xml' } } correctly uses success { junit } and always { archiveArtifacts }, meeting the goal.
  3. Final Answer:

    post { success { junit 'test-results/*.xml' } always { archiveArtifacts 'test-results/*.xml' } } -> Option A
  4. Quick Check:

    junit on success + archive always [OK]
Hint: Use success for junit, always for archiveArtifacts [OK]
Common Mistakes:
  • Putting junit in always block causing publish on failure
  • Swapping archiveArtifacts and junit blocks
  • Using failure block incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard