PDA

查看完整版本 : 如何在Matlab xUnit中将多个参数传递给共享相同设置代码的测试?


poster
2019-12-10, 16:49
根据“ 如何编写共享通用设置代码的测试 (http://www.mathworks.com/matlabcentral/fx_files/22846/7/content/matlab_xunit/doc/html/exTestFixtures.html) ”,可以:

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); 等等



更多&回答... (https://stackoverflow.com/questions/1477376)