主要内容

运行

类:matlab.unittest.TestCase
包:matlab.unittest

对应于测试用例的运行测试

描述

例子

结果=运行(testCase)运行所有的测试类定义的方法testCase并返回测试运行的结果matlab.unittest.TestResult数组,其中每个TestResult对象对应于一个测试方法。

运行交互式实验方法是一种方便的方法TestCase子类。它运行测试通过TestRunner实例配置为文本输出。文本输出包括测试运行进展以及诊断测试失败的事件。

例子

结果=运行(testCase,方法)运行指定的测试的方法testCase

输入参数

全部展开

指定为一个测试用例matlab.unittest.TestCase对象。

标识符的测试的方法testCase运行,指定为字符串标量,特征向量,或meta.method实例。

属性

密封 真正的

了解属性的方法,请参阅方法属性

例子

全部展开

测试的属性图通过创建并运行一个测试类。

在文件命名FigurePropertiesTest.m在当前文件夹,创建FigurePropertiesTest测试类:

  • 子类化的matlab.unittest.TestCase

  • 添加一个属性来表示图测试

  • 添加setup和teardown代码为每个测试TestMethodSetup方法

  • 添加测试测试方法

classdefFigurePropertiesTest < matlab.unittest.TestCase属性TestFigure结束方法(TestMethodSetup)函数createFigure testCase (testCase)。TestFigure =图;testCase.addTeardown (@close testCase.TestFigure)结束结束方法(测试)函数defaultCurrentPoint (testCase) cp = testCase.TestFigure.CurrentPoint;testCase。verifyEqual (cp [0 0),“默认当前点必须[0 0]。”)结束函数defaultCurrentObject (testCase)导入matlab.unittest.constraints.IsEmpty有限公司= testCase.TestFigure.CurrentObject;testCase.verifyThat (co、IsEmpty“默认当前对象必须是空的。”)结束结束结束

运行测试交互,创建一个测试用例的测试类。你也可以使用forInteractiveUse静态方法创建一个测试用例。

testCase = FigurePropertiesTest;

运行测试的测试用例。测试通过。

result1 =编写此表达式运行(testCase)
运行FigurePropertiesTest
。完成FigurePropertiesTest __________
result1 = 1×2编写此表达式TestResult数组属性:名称传递失败的不完整的时间细节总数:2了,失败了,0不完整,测试时间0.10772秒。

现在,运行defaultCurrentPoint测试方法。

result2 =运行(testCase,“defaultCurrentPoint”)
运行FigurePropertiesTest
。完成FigurePropertiesTest __________
result2 = TestResult属性:名称:“FigurePropertiesTest / defaultCurrentPoint”通过:1失败:0不完整:0时间:0.0553细节:[1×1 struct]总数:1通过,失败了,0不完整,测试时间0.055328秒。

版本历史

介绍了R2013a