Use MATLAB with Codecov
This example shows how to run MATLAB® tests, produce code coverage results, and upload the results to Codecov. The repository includes these files.
File Path | Description |
---|---|
source/quadraticSolver.m |
A function that solves quadratic equations |
tests/SolverTest.m |
A class that tests the quadraticSolver function |
runMyTests.m |
A script that creates a test suite and a test runner that produces code coverage results in Cobertura XML format |
azure-pipelines.yml |
A configuration example for Azure® DevOps |
.circleci/config.yml |
A configuration example for CircleCI® |
.github/workflows/workflow.yml |
A configuration example for GitHub® Actions |
Each of these pipeline definitions does four things:
- Install the latest MATLAB release on a Linux®-based build agent.
- Run all MATLAB tests in the root of your repository, including its subfolders.
- Produce code coverage results in Cobertura XML format for the
source
folder. - Upload the coverage artifact to Codecov.
pool:
vmImage: ubuntu-latest
steps:
- task: InstallMATLAB@1
- task: RunMATLABTests@1
inputs:
sourceFolder: source
codeCoverageCobertura: coverage.xml
- script: |
# download Codecov CLI
curl -Os https://cli.codecov.io/latest/linux/codecov
# integrity check
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step
curl -Os https://cli.codecov.io/latest/linux/codecov
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM.sig
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
# upload to Codecov
shasum -a 256 -c codecov.SHA256SUM
sudo chmod +x codecov
./codecov upload-process -t $(CODECOV_TOKEN)
version: 2.1
orbs:
matlab: mathworks/matlab@1
codecov: codecov/codecov@4
jobs:
build:
machine:
image: ubuntu-2204:current
steps:
- checkout
- matlab/install
- matlab/run-tests:
source-folder: source
code-coverage-cobertura: coverage.xml
- codecov/upload:
file: coverage.xml
name: Example
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: matlab-actions/setup-matlab@v2
- uses: matlab-actions/run-tests@v2
with:
source-folder: source
code-coverage-cobertura: coverage.xml
- uses: codecov/codecov-action@v4
with:
file: coverage.xml
If you encounter a product licensing issue, consider requesting a MATLAB batch licensing token by submitting the MATLAB Batch Licensing Pilot form.
If you have an enhancement request or other feedback, create an issue on the Issues page.
For support, contact MathWorks Technical Support.