![]() |
如何在Matlab xUnit中将多个参数传递给共享相同设置代码的测试?
根据“ [URL="http://www.mathworks.com/matlabcentral/fx_files/22846/7/content/matlab_xunit/doc/html/exTestFixtures.html"]如何编写共享通用设置代码的测试[/URL] ”,可以:
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'); 当我运行测试时,它说: [INDENT][INDENT]输入参数“ fc”未定义。 [/INDENT][/INDENT]这是为什么?我做错了什么,还是当前版本的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); 等等 [url=https://stackoverflow.com/questions/1477376]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:24。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.