No BSD License  

Highlights from
MUnit: a unit testing framework in Matlab

MUnit: a unit testing framework in Matlab

by

 

05 Jun 2006 (Updated )

A complete unit testing framework in Matlab

SfactoryTemplate(in)
% Desc of the testset.
function out = SfactoryTemplate(in)
% This code must be inserted in every test file.
out = str2func(in);

% ------------------------ LOCAL FUNCTIONS ------------------------

% This is the setup function, use this for fixtures:
function tso = MUnitSetUp(ts,event)
% Comment to the setup callback

% Code that generates the new ts:
tso = ts;

% -----------------------------------------------------------------

% This is the shoutdown function, use this for fixtures:
function tso = MUnitShoutDown(ts,event)
% Comment to the shoutdown callback

% Code that generates the new ts:
tso = ts;

% -----------------------------------------------------------------

% This is the reset callback called before each testunit test
function tuo = MUnitReset(tu,event)
% Comment to the reset callback

% Code that prepare the tuo test:
tuo = tu;

% -----------------------------------------------------------------

% This is the reset callback called after each testunit test
function tuo = MUnitDone(tu,event)
% Comment to the done callback

% Code that analize the tuo test:
tuo = tu;

% =================================================================

% This is an example of function used as test:
function [tuo,status,tdatao] = MUnitTest_ATest(tu,tdata)
% Comment

%  Code that computes the new version of tu and tdata, then returns
% a boolena status.
status = true;

% A list of asserts:
try
    % Check of a boolean assertion:
    % assertTrue(tu,<booleanExpression>,'Comment');
    assertTrue(tu,false,'Comment');
    % Check an operation that can fail with error:
    % try <operation>
    % catch failure(tu,'Comment'); end
    try error('Bad operation');
    catch failure(tu,'Comment'); end
catch
    % Bad!!!
    status = false;
end

% -----------------------------------------------------------------

% This is another example of function used as test:
function [tuo,status,tdatao] = MUnitTest_AnotherTest(tu,tdata)
% Comment

%  Code that computes the new version of tu and tdata, then returns
% a boolena status.
tuo = tu;
tdatao = tdata;
status = true;

Contact us