Use MATLAB with Codecov
This example shows how to run MATLAB® tests, produce a code coverage report, and upload the report 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 outputs a Cobertura code coverage report |
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 |
.travis.yml |
A configuration example for Travis CI |
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 a code coverage report in Cobertura XML format for the
source
folder. - Upload the produced artifact to Codecov.
pool:
vmImage: ubuntu-latest
steps:
- task: InstallMATLAB@0
- task: RunMATLABTests@0
inputs:
sourceFolder: source
codeCoverageCobertura: coverage.xml
- script: bash <(curl -s https://codecov.io/bash)
version: 2.1
orbs:
matlab: mathworks/matlab@0
codecov: codecov/codecov@1
jobs:
build:
machine:
image: ubuntu-2004:202104-01
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@v2
- uses: matlab-actions/setup-matlab@v1
- uses: matlab-actions/run-tests@v1
with:
source-folder: source
code-coverage-cobertura: coverage.xml
- uses: codecov/codecov-action@v1
with:
file: coverage.xml
language: matlab
script: matlab -batch 'runMyTests'
after_success: bash <(curl -s https://codecov.io/bash)
- Currently, MATLAB builds that use cloud-hosted agents are available only for public projects.
If you have any questions or suggestions, please contact MathWorks® at [email protected].