Bird
Raised Fist0
Jenkinsdevops~10 mins

JUnit test report publishing in Jenkins - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to publish JUnit test reports in a Jenkins pipeline.

Jenkins
post {
  always {
    junit '[1]'
  }
}
Drag options to blanks, or click blank then click option'
Asrc/test/java/*.java
Bpom.xml
C**/target/surefire-reports/*.xml
Dbuild.gradle
Attempts:
3 left
💡 Hint
Common Mistakes
Using source code file paths instead of report XML files.
Forgetting to include the wildcard for XML files.
2fill in blank
medium

Complete the code to archive JUnit test reports as artifacts after the build.

Jenkins
steps {
  archiveArtifacts artifacts: '[1]', allowEmptyArchive: true
}
Drag options to blanks, or click blank then click option'
Abuild/reports/tests/*.html
B**/target/surefire-reports/*.xml
Csrc/test/reports/*.xml
Dlogs/test.log
Attempts:
3 left
💡 Hint
Common Mistakes
Archiving HTML reports instead of XML files.
Using incorrect file paths that do not exist.
3fill in blank
hard

Fix the error in the Jenkins pipeline snippet to correctly publish JUnit test reports.

Jenkins
post {
  always {
    junit '[1]'
  }
}
Drag options to blanks, or click blank then click option'
Atarget/surefire-reports/*.txt
B**/target/surefire-reports/*.html
Ctarget/surefire-reports/*.xml
D**/target/surefire-reports/*.xml
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTML or TXT files instead of XML for JUnit reports.
Not using the recursive glob pattern when reports are in subfolders.
4fill in blank
hard

Fill both blanks to define a Jenkins pipeline stage that runs tests and publishes JUnit reports.

Jenkins
stage('Test') {
  steps {
    sh '[1]'
    junit '[2]'
  }
}
Drag options to blanks, or click blank then click option'
Amvn test
B**/target/surefire-reports/*.xml
Cnpm test
Dbuild/test-results/test/*.xml
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong test command for Maven projects.
Publishing reports from incorrect file paths.
5fill in blank
hard

Fill all three blanks to create a Jenkins pipeline snippet that runs tests, archives reports, and publishes JUnit results.

Jenkins
stage('Test') {
  steps {
    sh '[1]'
    archiveArtifacts artifacts: '[2]', allowEmptyArchive: true
    junit '[3]'
  }
}
Drag options to blanks, or click blank then click option'
Amvn test
B**/target/surefire-reports/*.xml
Dnpm test
Attempts:
3 left
💡 Hint
Common Mistakes
Using different paths for archiving and publishing reports.
Running tests with the wrong command.

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