Unit testing 如何在Matlab xUnit中将多个参数传递给共享相同设置代码的测试?
根据“”是否可以:Unit testing 如何在Matlab xUnit中将多个参数传递给共享相同设置代码的测试?,unit-testing,matlab,xunit,Unit Testing,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) assert
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要求每个函数都有一个端点。我在这里编写它们并不是为了与手动示例保持一致。框架只使用一个输出参数调用设置函数。如果要从设置函数传递更多信息,请将所有内容捆绑到结构中 此外,以下是使用end终止函数的规则。(这些规则于2004年在MATLAB 7.0中引入,自那时起没有改变。) 如果文件中的任何函数都以结束终止,则该文件中的所有函数都必须以结束终止 嵌套函数必须始终以结尾终止。因此,如果文件包含嵌套函数,则该文件中的所有函数都必须以结尾终止 classdef文件中的所有函数和方法都必须以结尾终止。只需使用结构:
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);
等等。谢谢你最后的解释=)