Unit Testing For Matlab
- From: Brad Phelan <bradphelan@xxxxxxxxxxxx>
- Date: Tue, 08 Nov 2005 21:40:15 +0100
Hi all,
I've released my Matlab unit testing toolbox MUnit at
http://xtargets.com/cms/index.php?option=content&task=view&id=19
It is trivial to use and comes with a ( IMHO ) a very nice browser based control panel and browser based reporting of test results.
The control panel and test report allows you to
* Run tests. * Debug tests. * Open the editor to the exact line where a test error occured. * See the full details of the assertion that failed. * Create new test cases using a test generation wizard * bookmark tests for easy access
The test file format is very simple and follows the standard unit test pattern of fixture setup and teardown with a number of tests. Using matlab nested functions this becomes extremely powerfull.
///////////////\\\\\\\\\\\\\\
function test = test_template
% Subclass the testcase object
test = munit_testcase; % Create a structure of constraint objects for assertions
c = munit_constraint; function setup
% This function will be called at the
% start of *every* test_ functionend
function teardown
% This function will be called at the
% end of *every* test_ function
end
% TEST_1 % % This is an example test. Create new tests by creating % new functions whose name starts with test_ function test_1
% Assert that 1 == 1 to pass
test.assert( c.eq( 1, 1 ) ); % Assert that ~(1 == 1) to fail
test.assert( c.not ( c.eq( 1, 1 ) ) );
end
end//////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
See the tutorial and download at
http://xtargets.com/cms/index.php?option=content&task=view&id=19
Note this toolbox requires Matlab Service Pack 3 due to a few feature enhancements Mathworks made.
Happy testing
Brad
PS. There is a bonus toolbox which you must install which is a text templating engine I used to generate the HTML reports for MUnit. It can be used for any text based generation and is much like PHP or Velocity but uses the Matlab language. Use it to generate HTML, XML, C-Code, M-Code etc etc.
See http://xtargets.com/cms/index.php?option=com_docman&task=cat_view&gid=10&Itemid=21
eg: ------------------------------------------
# function mtemplate_usecase1(rows)
<html>
<body>
# for i = 1:rows
<%=genline(i)%>
# end
</body>
</html> # function genline(row)
<p> <%= 1:row %> </p>
# end#end
-------------------------------------------
>> f = mtemplate_compile('mtemplate_usecase1.mt'); >> f(3) ans =
<html>
<body>
<p> 1 </p>
<p> 1 2 </p>
<p> 1 2 3 </p>
</body>
</html>( Note the license is GPL so if you use it in your own toolbox and distribute it you must also use a GPL license )
-- Brad Phelan http://xtargets.com .
- Follow-Ups:
- Re: Unit Testing For Matlab
- From: thomas
- Re: Unit Testing For Matlab
- From: per isakson
- Re: Unit Testing For Matlab
- Prev by Date: Re: Make one big matrix?
- Next by Date: Re: Make one big matrix?
- Previous by thread: Plotting an Arrow
- Next by thread: Re: Unit Testing For Matlab
- Index(es):
Relevant Pages
|
Loading