0
0
Jenkinsdevops~20 mins

Running unit tests in pipeline in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Unit Test Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Jenkins pipeline stage?

Consider this Jenkins pipeline snippet that runs unit tests using Maven:

stage('Test') {
  steps {
    sh 'mvn test'
  }
}

What will Jenkins display if the tests pass successfully?

Jenkins
stage('Test') {
  steps {
    sh 'mvn test'
  }
}
ABuild succeeded with test results shown in console output
BBuild failed due to test failures
CBuild succeeded but no test results are shown
DBuild skipped the test stage
Attempts:
2 left
💡 Hint

Think about what mvn test does and how Jenkins shows output.

Configuration
intermediate
2:00remaining
Which Jenkinsfile snippet correctly archives JUnit test results?

You want Jenkins to archive JUnit test reports after running tests. Which snippet correctly configures this?

A
steps {
  archiveArtifacts '**/target/surefire-reports/*.xml'
}
B
steps {
  junit '**/target/surefire-reports/*.xml'
}
C
post {
  success {
    junit '**/target/surefire-reports/*.xml'
  }
}
D
post {
  always {
    junit '**/target/surefire-reports/*.xml'
  }
}
Attempts:
2 left
💡 Hint

Archiving test results should happen regardless of build success or failure.

🔀 Workflow
advanced
2:30remaining
Order the Jenkins pipeline steps to run unit tests and publish results correctly

Arrange these Jenkins pipeline steps in the correct order to run unit tests and publish their results:

A2,3,1,4
B3,1,2,4
C3,2,1,4
D1,3,2,4
Attempts:
2 left
💡 Hint

Think about the logical order: get code, run tests, archive results, then notify.

Troubleshoot
advanced
2:00remaining
What error will occur if the test report path is incorrect in the Jenkinsfile?

Given this Jenkinsfile snippet:

post {
  always {
    junit '**/wrong-path/*.xml'
  }
}

What will Jenkins report after running tests?

Jenkins
post {
  always {
    junit '**/wrong-path/*.xml'
  }
}
ABuild succeeds with no warnings
BBuild fails with a syntax error
CNo test reports found, build marked as unstable
DBuild fails with a file not found exception
Attempts:
2 left
💡 Hint

Consider what happens if Jenkins cannot find any test report files.

Best Practice
expert
3:00remaining
Which Jenkins pipeline practice ensures reliable unit test execution in parallel stages?

You want to run unit tests in parallel stages for different modules. Which practice ensures tests run reliably without interfering with each other?

AUse separate workspace directories for each parallel stage
BRun all tests in a single stage sequentially
CDisable test result archiving to speed up the build
DUse the same workspace for all parallel stages to share files
Attempts:
2 left
💡 Hint

Think about file conflicts when running parallel jobs.