How to generate code coverage and cobertura test reports for the same source code in R2022b
Afficher commentaires plus anciens
I have used the following code to execute test prior to R2022b (R2018b-R2021b).
import matlab.unittest.TestRunner;
import matlab.unittest.TestSuite;
import matlab.unittest.plugins.CodeCoveragePlugin;
import matlab.unittest.plugins.XMLPlugin;
import matlab.unittest.plugins.codecoverage.CoberturaFormat;
import matlab.unittest.plugins.codecoverage.CoverageReport
import matlab.unittest.selectors.HasBaseFolder;
suite = testsuite(fullfile(pwd, 'tests'), 'IncludeSubfolders', true);
fprintf("Running %d tests.\n", length([{suite.ProcedureName}]));
runner = TestRunner.withTextOutput();
runner.addPlugin(XMLPlugin.producingJUnitFormat('results.xml'));
runner.addPlugin( ...
CodeCoveragePlugin.forFolder({'.'}, ...
'IncludingSubfolders', true, ...
'Producing', CoberturaFormat('coverage.xml') ...
) ...
);
runner.addPlugin( ...
CodeCoveragePlugin.forFolder({'.'}, ...
'IncludingSubfolders', true, ...
'Producing', CoverageReport('coverageReport') ...
) ...
);
results = runner.run(suite);
display(results.table);
assert( ...
~any([results.Failed]), ...
'At least one test failed in the test session.' ...
);
% Optional, opens the test results in the matlab browser
% open(fullfile("coverageReport","index.html"))
As of R2022b this code fails with the following error:
MATLAB:unittest:CoverageReport:CoverageSessionsWithOverlappingSourcesNotAllowed
Error using matlab.unittest.internal.coverage.CodeCoverageCollector/initialize
Simultaneously generating coverage reports for the same source files is not
supported.
I noticed in the R2022b docs a new section about generating coverage with two plugins that isn't in the R2018b-R2021b CodeCoveragePlugin document, but didn't notice any breaking change in the R2022b release notes to the CodeCoveragePlugin. Based on the R2022b documents it seems like we can't generate two reports for the same source code. Did the functionality change?
Thanks for any insights or help.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Run Unit Tests dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!