查看单个帖子
旧 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 当前离线   回复时引用此帖