matlab.uitest.TestCase.forInteractiveUse
类: matlab.uitest.TestCase
包: matlab.uitest
创建供交互测试的测试用例
说明
tc = matlab.uitest.TestCase.forInteractiveUse
创建一个为交互式测试配置的测试用例。返回的 TestCase
实例适合在命令提示符下进行试验。它通过向屏幕输出通过和失败事件的消息来响应验证。
示例
构造交互式 TestCase
创建一个红色信号灯组件,当按下按钮时,该组件变成绿色。
fig = uifigure; lamp = uilamp(fig,'Position',[50 100 20 20],'Color','red'); button = uibutton(fig,'ButtonPushedFcn',@(btn,event) set(lamp,'Color','green'));
创建一个配置为在 MATLAB® 命令提示符下交互使用的 TestCase
对象。
tc = matlab.uitest.TestCase.forInteractiveUse;
按下按钮。
tc.press(button)
验证信号灯的颜色为绿色。此测试失败,因为信号灯以 RGB 三元组形式存储颜色。
tc.verifyEqual(lamp.Color,'green')
Verification failed. --------------------- Framework Diagnostic: --------------------- verifyEqual failed. --> Classes do not match. Actual Class: double Expected Class: char Actual Value: 0 1 0 Expected char: green
验证信号灯的颜色是表示绿色的 RGB 三元组。
tc.verifyEqual(lamp.Color,[0 1 0])
Verification passed.
版本历史记录
在 R2018a 中推出
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)