Displaying test results and a code coverage report
Required plugins
Cobertura, JUnit Plugin
We are already running unit tests, but we can't see the result unless we go into the console output and look for it. The test result can be exposed in a nicer format using the JUnit plugin. While we're at it, let's also add a code coverage report:
- Open the Jenkinsfile and update the
Unit test
stage to generate two XML reports,junit.xml
for the unit test results andcoverage.xml
for the code coverage report:stage('Unit test') {
steps {
sh '''python3 -m pytest \
-v --junitxml=junit.xml \
--cov-report xml --cov adder adder.py
'''
} } - Also, add a
post
directive in theJenkinsfile
to pick up the two report files. Thepost
directive should be on the same level as thestages
directive:pipeline {
agent { ... }
stages...