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
sourcefolder. - 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.xmlname: 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.xmlIf you have any questions or suggestions, please contact MathWorks® at continuous-integration@mathworks.com.