0
0
Jenkinsdevops~5 mins

Running unit tests in pipeline in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of running unit tests in a Jenkins pipeline?
Running unit tests in a Jenkins pipeline helps catch code errors early by automatically checking if small parts of the code work correctly before moving forward.
Click to reveal answer
beginner
Which Jenkins pipeline step is commonly used to run shell commands like unit tests?
The sh step is used to run shell commands, such as executing unit test scripts or commands in a Jenkins pipeline.
Click to reveal answer
intermediate
How do you fail a Jenkins pipeline if unit tests fail?
If the unit test command returns a non-zero exit code, Jenkins marks the pipeline as failed automatically, stopping further steps.
Click to reveal answer
beginner
What is the benefit of using a 'stage' for unit tests in a Jenkins pipeline?
Using a separate 'stage' for unit tests organizes the pipeline clearly, making it easy to see test results and isolate test failures.
Click to reveal answer
beginner
Show a simple Jenkins pipeline snippet that runs unit tests using a shell command.
pipeline {
  agent any
  stages {
    stage('Unit Tests') {
      steps {
        sh 'python -m unittest discover'
      }
    }
  }
}
Click to reveal answer
What happens if unit tests fail in a Jenkins pipeline stage?
AThe pipeline skips the tests and moves on
BThe pipeline ignores the failure and continues
CThe pipeline retries the tests automatically
DThe pipeline stage fails and stops further execution
Which Jenkins pipeline syntax is used to run a shell command?
Ash
Bcmd
Crun
Dexecute
Why is it good practice to have a separate stage for unit tests in Jenkins?
ATo speed up the pipeline by skipping tests
BTo organize pipeline and clearly see test results
CTo run tests only after deployment
DTo avoid running tests automatically
What command might you use in a Jenkins pipeline to run Python unit tests?
Apython -m unittest discover
Bnpm test
Cmvn test
Dgradle build
In Jenkins, what does a non-zero exit code from a test command indicate?
APipeline success
BTest success
CTest failure
DNo tests run
Explain how to add unit tests to a Jenkins pipeline and what happens if tests fail.
Think about pipeline stages and shell commands.
You got /3 concepts.
    Describe the benefits of running unit tests automatically in a Jenkins pipeline.
    Consider how automation helps in software quality.
    You got /3 concepts.