Code covered by the BSD License  

Highlights from
mlunit_2008a

4.66667

4.7 | 3 ratings Rate this file 13 Downloads (last 30 days) File Size: 38.8 KB File ID: #21888
image thumbnail

mlunit_2008a

by

 

25 Oct 2008 (Updated )

A MATLAB unit test framework supporting new classdef files (r2008a)

| Watch this File

File Information
Description

mlunit_2008a originally began as an update to mlUnit (http://sourceforge.net/projects/mlunit/), also available from MATLAB Central file exchange. The purpose was to add support for the new "classdef" style classes in MATLAB 2008a. However, I got a bit carried away, and the "update" became more or less a complete rewrite.

In general, if you are comfortable with the "xUnit" style unit test frameworks (e.g., jUnit), then you'll be very comfortable with this tool. Creating tests involves subclassing a class named TestCase, then adding methods whose names begin with "test". Inside each method you can use the inherited validation methods (assert, assertEquals, assertNotEquals) to check for success or failure. All tests are run automatically and their results recorded and reported after the run.

The GUI is simple, but nice; it uses the undocumented uitree widget to give hierarchical test results, and you also get nice visual feedback from the icons and such. As with mlUnit, you click on failed tests to see the error messages and stacktrace; you can select a line in the stacktrace and click a button to open a code editor and place the cursor at that location in your code. You also get the ability to add tests via a multiselect file dialog, for quick and easy use.

For those of you who prefer to run headless, there is also a simple text test runner with a clear API.

A note of explanation: when I began this (soon after the 2008a release), I didn't realize that the mlUnit developers were also updating their code for the new style classes (mlUnit 2.0). As it turns out, I like my version better so I'm releasing it anyway :)

Warning: Uses the undocumented/unsupported uitree widget, which Mathworks warns may change or go away in a future release.

Acknowledgements

This file inspired Doctest Embed Testable Examples In Your Function's Help Comments and Dir Lot Toolbox.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
26 Jul 2013 per isakson

Now I've run the sample tests with R2013a. It works nicely. However, there were two minor problems.

Firstly, I cannot avoid the warning: "The selected tests appear to not be in your current path[...]" and accepts adding it. The reason seems to be the case of a drive letter. The variable, pname, has a capital "H" and path and pwd returns lower case "h". Here are some excerpts from my tracking the issue.

classdef GuiTestRunner < TestRunner
...
%%%%%%%%%%%%%
function addTestsCB(self, src, event)
[fnames, pname] = uigetfile('*.m', 'Add ...
...
if ~strcmp(pname, pwd)
k = strfind(path, pname);
if isempty(k)

K>> str = path;
K>> strfind( str, pname)
ans =
[]
K>> str(1:60)
ans =
h:\m\FEX\xUnit\mlunit_2008a\samples;h:\m\F...
K>> pwd
ans =
h:\m\FEX\xUnit\mlunit_2008a
K>> pname
pname =
H:\m\FEX\xUnit\mlunit_2008a\samples

Secondly, I had a run-time error, "Too many input ...", which I "magically" fixed by adding a tilde, "~", to the signature of the constructor, TestResult. Weird!

Too many input arguments.
Error in TestSuiteResult (line 12)
self = self@TestResult(varargin{:});
Error in TestSuite/getNewTestResult (line 24)
tr = TestSuiteResult(self, parent);
....

function self = TestResult(obj, par, ~ )

16 Jun 2011 Marcel RĂ¼land

Verry good. Easy to use and helps to avoid bad surprises due to hidden bugs in many cases.

12 May 2009 Peter Manley-Cooke

Very good. Simple usage and clear results. Easy installation is a bonus. Dynamic test suite composition, good.

Updates
15 Jul 2009

- now under BSD license
- fixed "clear classes" bug
- added support for packages

Contact us