Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab UnitTest Coverage

Matlab has a fancy new unit-testing framework in 2013a. I've found it quite helpful, but as my modules grow I would like to know how much coverage I have achieved. How can I measure my unit-test coverage, similar to how coverity et al would?

like image 287
danatron Avatar asked May 07 '13 17:05

danatron


People also ask

How do I check code coverage in Matlab?

Use LDRA tool suite or BullseyeCoverage to collect code coverage metrics during a SIL or PIL simulation. Use line commands to set up third-party code coverage analysis for a SIL or PIL simulation. Access results from third-party code coverage tools.

How do you create a coverage report in Matlab?

External MATLAB File Coverage Report If your top-level model calls any external MATLAB files, select MATLAB files on the Coverage pane in the Configuration Parameters dialog box. The software creates a report, named MATLAB_file_name _cov. html , for each distinct file called from the model.


1 Answers

Release 2014b provides a plugin to produce a code coverage report. For example:

import matlab.unittest.TestRunner;
import matlab.unittest.TestSuite;
import matlab.unittest.plugins.CodeCoveragePlugin;

% Create a TestSuite array
suite = TestSuite.fromFolder(testFolder);

% Create a runner and add the code coverage plugin
runner = TestRunner.withTextOutput;
runner.addPlugin(CodeCoveragePlugin.forFolder(sourceFolder));

% Run the suite. This opens a code coverage report when done testing.
result = runner.run(suite)

Note that the the coverage report should be run on your source code while the test suite is generated from a separate folder. If you use pwd as in the linked example, you'll get a coverage report of the tests that you just ran.

like image 135
David Hruska Avatar answered Sep 20 '22 21:09

David Hruska