then
类: matlab.mock.actions.DoNothing
命名空间: matlab.mock.actions
输入参数
action1
— 定义的动作
matlab.mock.actions.DoNothing
对象
定义的动作,指定为 matlab.mock.actions.DoNothing
对象。
示例: action1 = DoNothing
action2
— 第二个定义的动作
matlab.mock.actions.AssignOutputs
对象 | matlab.mock.actions.Invoke
对象 | matlab.mock.actions.StoreValue
对象 | matlab.mock.actions.ThrowException
对象
第二个定义的动作,指定为 matlab.mock.actions.AssignOutputs
、matlab.mock.actions.Invoke
、matlab.mock.actions.StoreValue
或 matlab.mock.actions.ThrowException
对象。
示例: action2 = AssignOutputs(7,13,42)
示例: action2 = ThrowException
示例
对 mock 方法调用不采取任何动作
为 bank account 类创建一个 mock。
testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedMethods',"deposit");
第一次调用 deposit
时不采取任何动作。第二次调用该方法时引发异常。
import matlab.mock.actions.DoNothing import matlab.mock.actions.ThrowException when(withAnyInputs(behavior.deposit),DoNothing().then(ThrowException))
使用 mock。方法调用不会引起任何动作。
mock.deposit(100)
再次调用 mock 方法。MATLAB® 抛出错误。
mock.deposit(100)
Error using matlab.mock.internal.MockContext/createMockObject/mockMethodCallback (line 382)
The following method call was specified to throw an exception:
deposit([1×1 matlab.mock.classes.Mock], 100)
提示
每次调用
then
时最多接受两项动作。要指定更多后续动作,请多次调用then
。例如,要指定三项动作,请使用action1.then(action2).then(action3)
。
版本历史记录
在 R2020a 中推出
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)