matlab.unittest.TestCase.forInteractiveUse
类: matlab.unittest.TestCase
命名空间: matlab.unittest
创建供交互测试的测试用例
语法
说明
输入参数
testClass
— 测试类
meta.class
实例
从 matlab.unittest.TestCase
派生的测试类,指定为 meta.class
实例。
示例: ?ExampleTest
示例
测试子字符串
测试 actual 值是否包含指定的子字符串。
创建一个供交互测试的测试用例。
testCase = matlab.unittest.TestCase.forInteractiveUse;
定义 actual 值。
actual = "This is a long message.";
验证 actual
包含文本 "long"
。
verifySubstring(testCase,actual,"long")
Verification passed.
展示大小写不同所造成的影响。此测试失败,因为 actual
不包含 "Long"
。
verifySubstring(testCase,actual,"Long","Test is case sensitive.")
Verification failed. ---------------- Test Diagnostic: ---------------- Test is case sensitive. --------------------- Framework Diagnostic: --------------------- verifySubstring failed. --> The value does not contain the substring. Actual Value: "This is a long message." Expected Substring: "Long" ------------------ Stack Information: ------------------ In C:\work\TestForSubstringsExample.m (TestForSubstringsExample) at 22
显示如果子字符串比实际字符串长,测试将失败。
verifySubstring(testCase,actual,"This is a long message with extra words.")
Verification failed. --------------------- Framework Diagnostic: --------------------- verifySubstring failed. --> The value does not contain the substring. Actual Value: "This is a long message." Expected Substring: "This is a long message with extra words." ------------------ Stack Information: ------------------ In C:\work\TestForSubstringsExample.m (TestForSubstringsExample) at 27
为指定的类创建交互式测试用例
以交互方式运行测试类的 Test
方法。
在当前文件夹中名为 ZerosTest.m
的文件中,创建 ZerosTest
类来测试 zeros
函数。
classdef ZerosTest < matlab.unittest.TestCase properties (TestParameter) type = {'single','double','uint16'}; size = struct("s2d",[3 3],"s3d",[2 5 4]); end methods (Test) function testClass(testCase,size,type) testCase.verifyClass(zeros(size,type),type) end function testSize(testCase,size) testCase.verifySize(zeros(size),size) end function testDefaultClass(testCase) testCase.verifyClass(zeros,"double") end function testDefaultSize(testCase) testCase.verifySize(zeros,[1 1]) end function testDefaultValue(testCase) testCase.verifyEqual(zeros,0) end end end
创建一个供交互测试的 ZerosTest
类的实例。
testCase = matlab.unittest.TestCase.forInteractiveUse(?ZerosTest);
以交互方式使用该测试用例调用 testSize
方法。测试通过。
testCase.testSize([5 10])
Verification passed.
版本历史记录
在 R2014a 中推出
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)