forked from mathworks/matlab-codecov-example
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runMyTests.m
27 lines (21 loc) · 1013 Bytes
/
runMyTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
% Copyright 2021 The MathWorks, Inc.
import matlab.unittest.TestRunner
import matlab.unittest.Verbosity
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.codecoverage.CoberturaFormat
% Add the source folder to the MATLAB search path
addpath('source')
% Create a test suite
suite = testsuite(pwd,'IncludeSubfolders',true);
% Create a test runner that displays test run progress at the matlab.unittest.Verbosity.Detailed level
runner = TestRunner.withTextOutput('OutputDetail',Verbosity.Detailed);
% Create a CodeCoveragePlugin instance and add it to the test runner
sourceFolder = 'source';
reportFile = 'cobertura.xml';
reportFormat = CoberturaFormat(reportFile);
p = CodeCoveragePlugin.forFolder(sourceFolder,'IncludingSubfolders', true,'Producing',reportFormat);
runner.addPlugin(p)
% Run the tests and fail the build if any of the tests fails
results = runner.run(suite);
nfailed = nnz([results.Failed]);
assert(nfailed == 0,[num2str(nfailed) ' test(s) failed.'])