-
Notifications
You must be signed in to change notification settings - Fork 0
/
runMyTests.m
22 lines (18 loc) · 903 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
import matlab.unittest.TestRunner
import matlab.unittest.Verbosity
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.codecoverage.CoberturaFormat
% 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.'])