Skip to content

Commit

Permalink
Update run_coverage_tests.m
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronBrennan1 authored Nov 5, 2024
1 parent 7d14232 commit 3bb9cc8
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions run_coverage_tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,41 @@
current_dir = pwd;

try
% Configure MOcov
cover_method = '-cover';
covered_dir = current_dir;
report_file = fullfile(current_dir, 'coverage.xml');

% Run tests and generate coverage
test_suite = testsuite('tests/test_myfunction.m');
results = run(test_suite);

% Check if all tests passed
num_failed = nnz([results.Failed]);
if num_failed > 0
error('Some tests failed');
end
% Import necessary components
import matlab.unittest.TestRunner;
import matlab.unittest.TestSuite;
import matlab.unittest.plugins.TestReportPlugin;
import matlab.unittest.plugins.CodeCoveragePlugin;

% Create test suite from the test file
suite = TestSuite.fromFile('tests/test_myfunction.m');

% Create a runner
runner = TestRunner.withTextOutput('Verbosity', 3);

% Add the coverage plugin
coveragePlugin = CodeCoveragePlugin.forFolder(current_dir, ...
'IncludingSubfolders', true, ...
'Producing', matlab.unittest.plugins.codecoverage.CoverageReport('coverage'));
runner.addPlugin(coveragePlugin);

% Generate coverage report
mocov(cover_method, covered_dir, '-cover_xml_file', report_file);
% Run the tests
results = runner.run(suite);

% Display summary
disp('Test Summary:');
disp(['Number of tests: ' num2str(numel(results))]);
disp(['Passed: ' num2str(nnz([results.Passed]))]);
disp(['Failed: ' num2str(nnz([results.Failed]))]);
disp(['Duration: ' num2str(sum([results.Duration])) ' seconds']);

% Generate MOcov coverage report
mocov('-cover', current_dir, '-cover_xml_file', 'coverage.xml');

% Check if any tests failed
if any([results.Failed])
error('Some tests failed. Check the test report for details.');
end

% Exit with success
exit(0);
Expand Down

0 comments on commit 3bb9cc8

Please sign in to comment.