主要内容

functiontests

从句柄到本地函数创建测试数组

描述

例子

测试= functiontests (f创建测试数组,测试,从句柄的单元格数组到局部函数,f.要应用定义的设置和拆卸函数,请将它们的函数句柄包含在f

局部测试函数必须在函数名的开头或结尾包含“test”。functiontests必须从测试文件中调用。

例子

全部折叠

创建文件exampleTest.m在你的MATLAB®路径。在main函数中,创建一个测试数组。使用局部函数定义设置、拆卸和两个函数测试。你的档案应该是这样的。

函数测试= functiontests(localfunctions);函数设置(testCase)函数拆卸(testCase)函数exampleOneTest (testCase)函数testExampleTwo (testCase)

从命令行调用exampleTest函数。

测试= exampleTest
Test = 1x2带有属性的测试数组:Name ProcedureName TestClass BaseFolder Parameterization SharedTestFixtures Tags tests包括:0 Parameterizations, 0 SharedTestFixture Classes, 0 Tags。

访问测试套件以验证两个功能测试的名称。

测试。的名字
ans = 'exampleTest/testExampleTwo' ans = 'exampleTest/testExampleTwo'

输入参数

全部折叠

局部测试函数的句柄,指定为单元格数组。使用f = localfunctions在您的工作文件中自动生成该文件的函数句柄的单元格数组。如果你想要显式的测试枚举,构造f通过列出单独的函数。f必须包含测试所需的任何安装或拆卸功能。

例子:f = localfunctions;

例子:f = {@setup, @exampleOneTest @teardown};

介绍了R2013b