Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 16:49   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在Matlab xUnit中将多个参数传递给共享相同设置代码的测试?

根据“ 如何编写共享通用设置代码的测试 ”,可以:

function test_suite = testSetupExample initTestSuite; function fh = setup fh = figure; function teardown(fh) delete(fh); function testColormapColumns(fh) assertEqual(size(get(fh, 'Colormap'), 2), 3); function testPointer(fh) assertEqual(get(fh, 'Pointer'), 'arrow'); 但是我无法使其与更多参数一起使用:

function test_suite = testSetupExample initTestSuite; function [fh,fc] = setup fh = figure; fc = 2; end function teardown(fh,fc) delete(fh); function testColormapColumns(fh,fc) assertEqual(size(get(fh, 'Colormap'), fc), 3); function testPointer(fh,fc) assertEqual(get(fh, 'Pointer'), 'arrow'); 当我运行测试时,它说:
输入参数“ fc”未定义。

这是为什么?我做错了什么,还是当前版本的Matlab xUnit不支持它?如何规避呢?

PS:实际上我的MATLAB要求每个函数都有一个结局。我没有在这里写它们以与手册示例保持一致。


回答:
只需使用一个结构:

function test_suite = testSetupExample initTestSuite; function [fh] = setup fh.one = figure; fh.two = 2; end function teardown(fh) delete(fh.one); function testColormapColumns(fh) assertEqual(size(get(fh.one, 'Colormap'), fc.two), 3); 等等



更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:05


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.