Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab单元测试覆盖率_Matlab_Unit Testing_Code Coverage - Fatal编程技术网

Matlab单元测试覆盖率

Matlab单元测试覆盖率,matlab,unit-testing,code-coverage,Matlab,Unit Testing,Code Coverage,Matlab在2013a有一个新奇的单元测试框架。我发现它非常有用,但随着我的模块的增长,我想知道我已经实现了多少覆盖率。我如何衡量我的单元测试覆盖率,就像coverity等人所做的那样?也许我的评论不够清晰。例如,让我们创建简单的函数: 文件夹/test1.m 接下来,从“当前文件夹”小部件中,选择“报告>覆盖率报告”: 这将为您提供当前文件夹中所有函数/脚本的覆盖率报告: 单击链接将打开常规配置文件查看器: 显然,您可以直接从概要文件查看器中为每个文件选择上述选项…2014b版提供了生

Matlab在2013a有一个新奇的单元测试框架。我发现它非常有用,但随着我的模块的增长,我想知道我已经实现了多少覆盖率。我如何衡量我的单元测试覆盖率,就像coverity等人所做的那样?

也许我的评论不够清晰。例如,让我们创建简单的函数:

文件夹/test1.m 接下来,从“当前文件夹”小部件中,选择“报告>覆盖率报告”:

这将为您提供当前文件夹中所有函数/脚本的覆盖率报告:

单击链接将打开常规配置文件查看器:

显然,您可以直接从概要文件查看器中为每个文件选择上述选项…

2014b版提供了生成代码覆盖率报告的方法。例如:

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)

请注意,覆盖率报告应该在源代码上运行,而测试套件是从单独的文件夹生成的。如果您像链接的示例中那样使用
pwd
,您将得到一个刚刚运行的测试的覆盖率报告。

IDE包含了一个覆盖率工具(已经存在了很长一段时间)。它是分析器本身。
>> profile on
>> test1
>> profile off
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)