Согласно документации Matlab xUnit: вы можете либо 1) наследовать от TestCase, либо 2) использовать подфункции.Пример использования подфункций показан ниже.Вы можете передать только одну переменную, поэтому вам нужно загрузить их в структуру, как показано ниже.Вы можете поставить дополнительные подфункции в конце, но убедитесь, что вы начинаете или заканчиваете их имена с «setup», «test» или «teardown»
function test_suite = testjkcmInputParser
initTestSuite;
function d = setup
d.file='garbagelog.log';
d.fid = fopen(d.file, 'w');
d.o = jkcmInputParser(d.fid);
function teardown(d)
delete(d.o);
fclose(d.fid);
delete(d.file);
function testConstructorNoInput(d)
%constructor without fid
delete(d.o);
d.o = jkcmInputParser();
assertEqual(isa(d.o,'jkcmInputParser'), true, 'not a jkcmInputParser');
assertEqual(isa(d.o,'inputParser'), true, 'not an inputParser');
function testConstructorWithInput(d)
%constructor with fid
assertEqual(isa(d.o,'jkcmInputParser'), true, 'not a jkcmInputParser');
assertEqual(isa(d.o,'inputParser'), true, 'not an inputParser');
initializejkcmParser(d.o);
s = d.o.printHelp();
assertEqual(s, correctPrintHelp(), 'output of printHelp does not match expected.');
function outP = initializejkcmParser(o)
%setup jkcmInputParser
o.addRequired('val1_noComment', @isnumeric);
o.addRequired('val2', @isnumeric, 'comment');
o.addOptional('val3_noComment',3, @isnumeric);
o.addOptional('val4',15, @isnumeric, 'another great comment!');
o.addParamValue('val5_noComment', 45, @isnumeric);
o.addParamValue('val6', 45, @isnumeric, 'This is the greatest comment');
outP = o;
function outP = correctPrintHelp()
outP = sprintf(...
['val1_noComment: Req : \n',...
'val2: Req : comment\n',...
'val3_noComment: Opt : \n',...
'val4: Opt : another great comment!\n',...
'val5_noComment: Param : \n',...
'val6: Param : This is the greatest comment\n']);