Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple parameters to tests that share the same setup code in Matlab xUnit?

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.

like image 397
Jader Dias Avatar asked Dec 22 '22 08:12

Jader Dias


1 Answers

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.

like image 164
Steve Eddins Avatar answered Dec 28 '22 08:12

Steve Eddins