如何在Matlab xUnit中将多个参数传递给共享相同设置代码的测试? [英] How to pass multiple parameters to tests that share the same setup code in Matlab xUnit?

查看:194
本文介绍了如何在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');

但是我无法使其与更多参数一起使用:

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

我进行测试时说:

输入参数"fc"未定义.

Input argument "fc" is undefined.

那是为什么?我做错了什么,还是当前版本的Matlab xUnit不支持它?如何规避呢?

Why is that? I done something wrong or it is unsupported in the current version of Matlab xUnit? How to circumvent that?

PS:实际上我的MATLAB要求每个函数都有一个结尾.我在这里没有写它们是为了与手册示例保持一致.

PS: Actually my MATLAB requires each function to have an end. I didn't wrote them here to keep consistency with the manual examples.

推荐答案

只需使用一个结构:

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

这篇关于如何在Matlab xUnit中将多个参数传递给共享相同设置代码的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆