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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With