From 1f5f93af9d4c8afdc98af91eed963ea8b9aa1e59 Mon Sep 17 00:00:00 2001 From: Andrew Simms Date: Thu, 30 Nov 2023 13:47:05 -0700 Subject: [PATCH] Tests: Add code coverage Use built in MATLAB code coverage tool to generate code coverage report. There are two warnings when this runs for which fixes are not readily apparent: Warning: Coverage result is empty for check_range.m because the file is invalid. Warning: Coverage result is empty for blade_moments.m because the file is invalid. These two warnings indicate that code coverage is not being generated for those files. --- mhkit/tests/runTests.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mhkit/tests/runTests.m b/mhkit/tests/runTests.m index 7dd499a43..f60e6ed0d 100644 --- a/mhkit/tests/runTests.m +++ b/mhkit/tests/runTests.m @@ -3,6 +3,9 @@ import matlab.unittest.TestRunner; import matlab.unittest.TestSuite; import matlab.unittest.plugins.TestReportPlugin; + import matlab.unittest.plugins.CodeCoveragePlugin; + import matlab.unittest.plugins.codecoverage.CoverageReport; + % Define test suite testFileName = mfilename('fullpath'); @@ -22,6 +25,14 @@ plugin = TestReportPlugin.producingPDF(pdfFile); runner.addPlugin(plugin); + % Add Code Coverage Report + sourceCodeFolder = fileparts(testsFolder); + codeCoverageFolder = fullfile(testsFolder, 'coverage_report'); + reportFormat = CoverageReport(codeCoverageFolder); + + p = CodeCoveragePlugin.forFolder(sourceCodeFolder, Producing=reportFormat, IncludingSubfolders=true); + runner.addPlugin(p); + % Run the tests results = runner.run(suite);