Using the PublishCodeCoverageResults@2 task, you can publish multiple code coverage reports. According to its documentation, multiple summary files are merged into a single report.
For instance, consider this project setup:
|- backend
|- requirements.txt
|- ...
|- frontend
|- package.json
|- ...
|- azure-pipelines.yaml
|- docker-compose.yaml
|- README.md
The backend
folder contains a FastAPI application that serves API to the frontend service. The frontend
folder contains a Vue.js application (generated by Vite) that visualizes the data, retrieved from the backend service.
The content of the azure-pipelines.yaml
file is the following:
stages:
- stage: Test
displayName: Test and Lint Stage
jobs:
- job: Backend
displayName: Test and Lint Backend Service
pool:
vmImage: $(vmImageName)
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.10'
- script: python -m pip install --upgrade pip setuptools
displayName: Upgrade pip and setuptools
- script: python -m pip install -r $(backendDirName)/requirements.txt -r $(backendDirName)/requirements-dev.txt
displayName: Install all dependencies
- script: pre-commit run --all-files
workingDirectory: $(backendDirName)
displayName: Check code quality
- script: |
coverage run -m pytest
coverage xml -o coverage.xml
workingDirectory: $(backendDirName)
displayName: Generate coverage report
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: '**/coverage.xml'
- job: Frontend
displayName: Test and Lint Frontend Service
pool:
vmImage: $(vmImageName)
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
checkLatest: true
- script: npm install
workingDirectory: $(frontendDirName)
displayName: Install all dependencies
- script: npm run lint
workingDirectory: $(frontendDirName)
displayName: Check code quality
- script: npm run coverage
workingDirectory: $(frontendDirName)
displayName: Generate coverage report
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: '**/clover.xml'
There are five major steps for the backend and the frontend service.
- Configuring the environment: Python 3.10 version is used for the backend. Node 18 version is used for the frontend service.
- Installing dependencies: Dependencies are installed by using
pip
and npm
tools. Make sure that you include coverage
+ pytest
and the @vitest/coverage-v8
packages (or similar) in your dependencies.
- Linting source code (optional): Checking code quality using
pre-commit
and eslint
tools. Install them before execution.
- Generating code coverage: The Coverage.py for the backend and the Vitest for the fronted were used to create the coverage report.
- Publishing coverage report: At the end, the reports were published by
PublishCodeCoverageResults@2
tasks. It collects the coverage.xml
report for the backend and the clover.xml
for the frontend.
Note that, the workingDirectory
parameter ensures to start of the scripts in different directories.
When the pipeline is finished, it merges the two reports together. Navigate to the Code Coverage tab under the Pipelines page.
As you can see, the code coverage reports are present. It also calculates the average code coverage across the services.