0
0
Jenkinsdevops~20 mins

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

Choose your learning style9 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.