run
类: matlab.unittest.TestCase
命名空间: matlab.unittest
运行与测试用例对应的测试
说明
result = run(
运行定义 testCase
)testCase
的类的所有 Test
方法,并以 matlab.unittest.TestResult
数组形式返回测试运行的结果,其中每个 TestResult
对象对应于一个 Test
方法。
run
方法是用来与 TestCase
子类进行交互式试验的便利方法。它通过使用为文本输出配置的 TestRunner
实例来运行测试。文本输出包括测试运行进度以及在测试失败时的诊断。
输入参数
示例
创建并运行测试类
通过创建和运行测试类来测试图窗的属性。
在当前文件夹的名为 FigurePropertiesTest.m
的文件中,通过以下操作创建 FigurePropertiesTest
测试类:
子类化
matlab.unittest.TestCase
类添加属性来表示要测试的图窗
为
TestMethodSetup
methods
代码块中的每个测试添加设置和拆解代码在
Test
methods
代码块中添加测试
classdef FigurePropertiesTest < matlab.unittest.TestCase properties TestFigure end methods (TestMethodSetup) function createFigure(testCase) testCase.TestFigure = figure; testCase.addTeardown(@close,testCase.TestFigure) end end methods (Test) function defaultCurrentPoint(testCase) cp = testCase.TestFigure.CurrentPoint; testCase.verifyEqual(cp,[0 0], ... "Default current point must be [0 0].") end function defaultCurrentObject(testCase) import matlab.unittest.constraints.IsEmpty co = testCase.TestFigure.CurrentObject; testCase.verifyThat(co,IsEmpty, ... "Default current object must be empty.") end end end
为了以交互方式运行测试,请基于测试类创建一个测试用例。您还可以使用 forInteractiveUse
静态方法来创建一个测试用例。
testCase = FigurePropertiesTest;
运行与测试用例对应的测试。两个测试都通过。
result1 = run(testCase)
Running FigurePropertiesTest
.
. Done FigurePropertiesTest __________
result1 = 1×2 TestResult array with properties: Name Passed Failed Incomplete Duration Details Totals: 2 Passed, 0 Failed, 0 Incomplete. 0.10772 seconds testing time.
现在,运行 defaultCurrentPoint
Test
方法。
result2 = run(testCase,"defaultCurrentPoint")
Running FigurePropertiesTest
. Done FigurePropertiesTest __________
result2 = TestResult with properties: Name: 'FigurePropertiesTest/defaultCurrentPoint' Passed: 1 Failed: 0 Incomplete: 0 Duration: 0.0553 Details: [1×1 struct] Totals: 1 Passed, 0 Failed, 0 Incomplete. 0.055328 seconds testing time.
版本历史记录
在 R2013a 中推出
另请参阅
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)