如何将多个参数传递给在 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要求每个函数都有一个结束。我没有将它们写在这里是为了与手动示例保持一致。
According to "How to Write Tests That Share Common Set-Up Code" is it possible to:
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');
But I couldn't make it work with more parameters:
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');
When I runtests it says:
Input argument "fc" is undefined.
Why is that? I done something wrong or it is unsupported in the current version of Matlab xUnit? How to circumvent that?
PS: Actually my MATLAB requires each function to have an end. I didn't wrote them here to keep consistency with the manual examples.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该框架仅使用单个输出参数调用您的设置函数。如果您想从设置函数中传递更多信息,请将所有内容捆绑到一个结构中。
另外,这里是用 end 终止函数的规则。 (这些规则于 2004 年在 MATLAB 7.0 中引入,此后一直没有更改。)
如果文件中的任何函数以 end 终止,则该文件中的所有函数都必须以 end 终止。
嵌套函数必须始终以 end 结束。因此,如果文件包含嵌套函数,则该文件中的所有函数都必须以 end 结束。
classdef 文件中的所有函数和方法都必须以 end 结束。
The framework only calls your setup function with a single output argument. If you want to pass more information out from your setup function, bundle everything into a struct.
Also, here are the rules for terminating a function with end. (These rules were introduced in MATLAB 7.0 in 2004 and have not changed since then.)
If any function in a file is terminated with an end, then all functions in that file must be terminated with an end.
Nested functions must always be terminated with an end. Therefore, if a file contains a nested function, then all functions in that file must be terminated with an end.
All functions and methods in classdef files must be terminated with an end.
只需使用结构:
等。
Just use a struct:
etc.