0
0
Jenkinsdevops~20 mins

Code coverage reports in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Code Coverage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Jenkins Pipeline: Code Coverage Report Generation
Given this Jenkins pipeline snippet, what will be the output after running the jacoco step?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building project...'
      }
    }
    stage('Test') {
      steps {
        echo 'Running tests...'
      }
    }
    stage('Code Coverage') {
      steps {
        jacoco execPattern: '**/target/*.exec', classPattern: '**/classes', sourcePattern: '**/src/main/java'
      }
    }
  }
}
AThe pipeline runs but does not generate any coverage report because no test execution is specified.
BThe pipeline generates a JaCoCo code coverage report and archives it in Jenkins for visualization.
CThe pipeline fails because the <code>jacoco</code> step is not recognized in Jenkins pipelines.
DThe pipeline generates a test report but no code coverage report.
Attempts:
2 left
💡 Hint
The jacoco step in Jenkins pipelines is used to collect and publish code coverage reports.
Troubleshoot
intermediate
2:00remaining
Troubleshooting Missing Coverage Data in Jenkins
A Jenkins job runs tests and uses JaCoCo for coverage, but the coverage report shows 0% coverage. What is the most likely cause?
AThe JaCoCo exec files were not generated because tests did not run with the JaCoCo agent enabled.
BThe Jenkins workspace was cleaned before running tests, deleting coverage data.
CThe <code>jacoco</code> step was placed before the test execution stage in the pipeline.
DThe Jenkins server does not have enough memory to generate the coverage report.
Attempts:
2 left
💡 Hint
Coverage data depends on tests running with the coverage agent active.
Configuration
advanced
2:00remaining
Configuring Jenkins to Fail Build on Low Coverage
Which Jenkins pipeline snippet correctly fails the build if code coverage is below 80% using JaCoCo plugin?
Ajacoco execPattern: '**/target/*.exec', classPattern: '**/classes', sourcePattern: '**/src/main/java', changeBuildStatus: true, minimumInstructionCoverage: '80'
Bjacoco execPattern: '**/target/*.exec', classPattern: '**/classes', sourcePattern: '**/src/main/java', minimumInstructionCoverage: 80, failBuild: true
Cjacoco execPattern: '**/target/*.exec', classPattern: '**/classes', sourcePattern: '**/src/main/java', changeBuildStatus: true, minimumInstructionCoverage: '80%'
Djacoco execPattern: '**/target/*.exec', classPattern: '**/classes', sourcePattern: '**/src/main/java', failBuildOnLowCoverage: true, minimumCoverage: 80
Attempts:
2 left
💡 Hint
Check the official JaCoCo plugin documentation for correct parameter names and types.
🔀 Workflow
advanced
2:00remaining
Best Workflow to Collect Coverage from Multiple Modules
You have a multi-module Maven project. How should you configure Jenkins to collect JaCoCo coverage reports from all modules correctly?
ARun tests only in the root module and use <code>jacoco</code> step with execPattern '**/target/*.exec' to collect coverage.
BRun tests separately for each module and call <code>jacoco</code> step individually for each module's exec file.
CRun <code>mvn clean install</code> and rely on Jenkins to auto-detect coverage files without specifying patterns.
DRun <code>mvn clean verify</code> at root, then use <code>jacoco</code> step with execPattern '**/target/*.exec' to collect all coverage files.
Attempts:
2 left
💡 Hint
Maven multi-module builds generate coverage files in each module's target directory.
Best Practice
expert
3:00remaining
Ensuring Accurate Coverage Reports in Jenkins Pipelines
Which practice ensures the most accurate and reliable code coverage reports in Jenkins pipelines using JaCoCo?
ARun tests without JaCoCo agent and rely on Jenkins to generate coverage from compiled classes.
BRun <code>jacoco</code> step before tests to initialize coverage collection, then run tests normally.
CRun tests with JaCoCo agent enabled, archive exec files as artifacts, and run <code>jacoco</code> step after tests complete.
DRun tests with JaCoCo agent but do not archive exec files; just run <code>jacoco</code> step to generate report.
Attempts:
2 left
💡 Hint
Coverage data must be collected during test execution and preserved for reporting.