文档

matlab.mock.TestCase类

包:matlab.mock
超类:matlab.unittest.TestCase

TestCase使用mocking框架编写测试

描述

使用matlab.mock.TestCase类编写使用模拟框架的测试。的matlab.mock.TestCase源自于matlab.unittest.TestCase类。

建设

测试框架构造matlab.mock.TestCase实例。

方法

assertAccessed 断言一个属性被访问了
assertCalled 断言用特定的输入值调用了一个方法
assertNotAccessed 断言一个属性没有被访问
assertNotCalled 断言没有使用某些输入值调用方法
assertNotSet 断言没有设置属性
assertSet 断言设置了一个属性
assignOutputsWhen 定义方法调用或属性访问的返回值
assumeAccessed 假设访问了一个属性
assumeCalled 假设使用特定的输入值调用一个方法
assumeNotAccessed 假设没有访问某个属性
assumeNotCalled 假设没有使用某些输入值调用某个方法
assumeNotSet 假设没有设置属性
assumeSet 假设设置了一个属性
createMock 创建模拟对象
fatalAssertAccessed 致命地断言某个属性被访问了
fatalAssertCalled 致命地断言调用某个方法时使用了某些输入值
fatalAssertNotAccessed 致命地断言一个属性没有被访问
fatalAssertNotCalled 致命地断言没有使用某些输入值调用某个方法
fatalAssertNotSet 致命地断言没有设置属性
fatalAssertSet 致命地断言设置了一个属性
forInteractiveUse 创建TestCase互动使用
returnStoredValueWhen 返回存储的属性值
storeValueWhen 储存财产价值
throwExceptionWhen 为方法调用或属性交互抛出异常
verifyAccessed 验证是否访问了属性
verifyCalled 验证使用特定输入值调用的方法
verifyNotAccessed 验证未访问属性
verifyNotCalled 验证没有使用某些输入值调用方法
verifyNotSet 验证未设置属性
verifySet 验证是否设置了属性

继承的方法

addTeardown 动态添加拆卸例程
applyFixture 使用固定装置TestCase
forInteractiveUse 为交互使用创建TestCase
getSharedTestFixtures 提供对共享测试装置的访问
日志 记录诊断信息
onFailure 动态添加测试失败的诊断
运行 运行TestCase测验

此外,TestCase类从这些类继承方法:

matlab.unittest.qualifications.Assertable 验证测试的先决条件
matlab.unittest.qualifications.Assumable 筛选测试内容的资格
matlab.unittest.qualifications.FatalAssertable 中止测试执行的资格
matlab.unittest.qualifications.Verifiable 软失效条件的生产资格

复制语义

句柄。要了解句柄类如何影响复制操作,请参见复制对象

例子

全部展开

使用模拟编写一个测试。

进口matlab.unittest.constraints.IsLessThan;testCase = matlab.mock.TestCase.forInteractiveUse;为银行账户类创建一个模拟。[mock, behavior] = testCase.createMock(“AddedMethods”,[“存款”“isOpen”]);%设置行为testCase.throwExceptionWhen (behavior.deposit (IsLessThan (0)),...MException (的账户存款:负...“存款金额必须为正。”));%使用模拟对象mock.deposit (100);testCase.verifyError (@ () mock.deposit (-10),的账户存款:负);%通过验证testCase.verifyCalled (behavior.deposit (100),...他说,应该存入100美元。);testCase.assertNotCalled (behavior.deposit (0));testCase.assertCalled (behavior.deposit (IsLessThan (0)));%断言失败testCase.assertCalled (withExactInputs (behavior.isOpen));

在R2017a中介绍

这个话题有帮助吗?