Search Comments and Ratings

go

   
Date File Comment by Comment Rating
27 Oct 2013 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Keith - On my Mac, MATLAB xUnit passes 150 of the 151 test cases in its own test suite. (The one failure seems to be a bad test case.) Use the contact form on my author page (http://www.mathworks.com/matlabcentral/fileexchange/authors/22204) to send me more details about the problem you are experiencing.

16 Oct 2013 Image overlay Overlay a binary mask onto an image using a specified color Author: Steve Eddins Steve Eddins

Image Analyst, thanks for your comments. I like your suggestion about accepting the output of bwboundaries as the 2nd input argument. I don't really understand your comment about bwperim, though.

22 Jul 2013 Image overlay Overlay a binary mask onto an image using a specified color Author: Steve Eddins Steve Eddins

Andrew, you'll have to either pad or resize one of the images to match the other size to overlay them using this function. You could also consider using MATLAB graphics transparency features to overlay one image on another.

11 Mar 2013 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

David,

You say, "I believe that xUnit creates a new object for each method in that class for testing rather than iterating through the methods of a single (subclassed) TestCase object." That's correct, and that's a classic xUnit design pattern to ensure order independence of individual test methods. See http://martinfowler.com/bliki/JunitNewInstance.html.

Although it's possible to consider adding setup and teardown methods on a TestSuite level, I haven't done so for MATLAB xUnit.

Because of the release of a new unit testing framework in MATLAB itself (in R2013a), I probably will not put further effort into developing my MATLAB xUnit package. If you can upgrade to R2013a, I encourage you to give the new testing framework a try.

26 Feb 2013 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Daniel, you are correct.

18 Feb 2013 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Michael - no, I don't know anything about that.

06 Jul 2012 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Stefan, are you trying to nest your test functions inside the top-level functions? That is not supported.

There should be no problem terminating your functions with "end" as long as you are not trying to nest them.

05 Jul 2012 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Chris, the setup and teardown methods are intended to be called for each test case method that is executed. That's the normal xUnit style. It makes the test cases independently executable.

17 Apr 2012 Image overlay Overlay a binary mask onto an image using a specified color Author: Steve Eddins Steve Eddins

Lasse - thanks, I have uploaded a new version based on your suggestion.

09 Mar 2012 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Patrice, it is likely that you have made a coding error of some sort in constructing your test files. That would explain why the test suite appears to be empty. Try placing one of your test files outside of a package and running it directly to see if it does what you expect.

09 Mar 2012 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Federico, if you want to use a simple script as a test case you can. Follow the example in exQuickStart.html.

If you want to use subfunctions as multiple test cases in a single file, then you must use the function line at the top of the file because scripts in MATLAB can't contain functions.

01 Mar 2012 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Emmet, assertAlmostEqual has been obsolete since version 2.0 of MATLAB xUnit, which was released 2.5 years ago. It has been superseded by assertElementsAlmostEqual and assertVectorsAlmostEqual. The assertAlmostEqual function is only mentioned in the doc in two places: release-history.html, which tells you when it became obsolete, and the main doc page, xunit_product_page.html, which tells you where you can find it if you still need it (in the obsolete folder).

MATLAB xUnit works just fine in R2011a. Try running its own test suite by adding the xunit folder to the path, changing to the tests directory, and typing runtests. 151 test cases execute successfully in R2011a, including a large number of cases testing the subfunction style.

Automatic test case discovery in ordinary functions is difficult to implement because the MATLAB language has barely enough functionality to do it. As you noted, it requires the use of a script and an undocumented variant of which. When a test writer makes a coding error writing test case files, it isn't easy to determine what is wrong with the file other than it errors out when run, or that it doesn't appear to contain any test cases.

But it does work. My own test suite for the MATLAB files in the book Digital Image Processing Using MATLAB is written entirely using subfunction-style tests and MATLAB xUnit.

I suggest that you start with the working example shown in the doc file exSubfunctionTests.html and go from there.

20 Dec 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Maddy, I'm sorry, but I am not familiar with the details of deploying applications using the MATLAB Compiler.

20 Dec 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Maddy, the directory containing your tests needs to be on the MATLAB path in order for MATLAB to run the test code found in that directory.

15 Dec 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Jan, if all the tests are in the same directory, and if you only want to run a subset of the tests, but there's no naming pattern to easily select the desired subset, then ... the only suggestion I can think of is to write a script to automate the tediousness of typing in all the test file names manually.

05 Dec 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Jan, write a function to do it. How do you know which test cases should be selected? By some name pattern, or some other criteria?

02 Dec 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Jan, try using the static method TestSuite.fromTestCaseClassName().

25 Oct 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Dennis, thanks for the suggested fix.

21 Oct 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

James, thanks for the suggestion.

30 Aug 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Federico - No.

14 Jul 2011 TIMEIT Benchmarking Function TIMEIT.M measures the time required to call a user-specified function Author: Steve Eddins Steve Eddins

Andy, I don't fully understand your question. What do you mean by "warm in the time," for example? But I would guess that you're looking for something like this:

x = zeros(1024, 1024);
timeit(@() fft2(x))

08 Jun 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Matthew, good question. I suggest that you create a "helper" subfunction, something that doesn't begin or end with "test", that creates an object and then does:

myObj.my3Vector = [1 1];

Then you can create a test case that does this:

assertExceptionThrown(@helperFun, 'myClass:3Vec');

29 Mar 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Luke, files that begin or end with "[tT]est" are treated as test files. See this doc page: http://www.mathworks.com/matlabcentral/fx_files/22846/11/content/matlab_xunit/doc/html/exTestCaseSearching.html

09 Feb 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Daniel, usually this means that one or more test files are incorrectly written, possibly by omitting the output argument "test_suite" from the function definition line. Take a careful look at this doc page and make sure your test files are written as described: http://www.mathworks.com/matlabcentral/fx_files/22846/11/content/matlab_xunit/doc/html/exSubfunctionTests.html

I will see if I can make the harness smarter about recognizing this kind of malformed test file and producing helpful messages.

28 Jan 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Andrew, there's no special trick I know about for unit testing private methods.

27 Jan 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Andrew, MATLAB xUnit framework code runs in MATLAB with no special scope privileges, so it cannot run private-directory code directly. One possibility is to reorganize your code to put private-directory functions into a package instead. Another possibility is to put a "gateway" function in the directory above the private directory that returns a structure of function handles to the private functions you want to test.

27 Jan 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

I am collaborating with Prof. Diane Kelly (Royal Military College, kelly-d@rmc.ca) and Prof. Greg Wilson (University of Toronto, gvwilson@cs.utoronto.ca) on a study to explore how engineers and scientists test their software, and I'd like to invite you to help.

If you use MATLAB xUnit or a similar unit testing framework to test your MATLAB programs, and if you are willing to let us have a look at the tests you have written and the code that they exercise, please get in touch with us by sending e-mail to research@software-carpentry.org.

Ethical guidelines for the study are posted here: http://software-carpentry.org/research/

Thanks for your help!

23 Jan 2011 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Andrew, thanks for your comments. Only class methods go into a class folders, so you should definitely move the test files elsewhere.

14 Nov 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Thanks, Jeff. I've made a note to update the documentation regarding this point.

11 Nov 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Hi Jeff. I would prefer to keep the functional definition for setup and teardown as simple as possible. When I need to return multiple pieces of data from setup, I just bundle all the pieces into a single struct.

02 Nov 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Cengiz - No, I haven't done anything with Andrei's suggestion. Your own assert case is already supported by assertElementsAlmostEqual by specifying 'absolute' for the tolerance type.

28 Oct 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Michael, the framework doesn't call the stub, your function computeProjectTime does. The framework doesn't have any way to change MATLAB function name resolution rules in order for your function to call something else instead.

27 Oct 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Michael, it sounds like providing a test stub for a portion of the system under test is the responsibility of a test writer, not the test harness.

22 Oct 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Hi Michael ... I don't know what that means.

30 Sep 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Michael - test_suite is a TestSuite object. This is how the framework gathers up all the test cases into one big hierarchical test suite and then runs them all together. Call one of your test files with an output argument to see what this thing looks like.

There's no HTML reporting tool.

08 Jul 2010 Upslope area functions Functions for computing and visualizing upslope area, influence map, dependence map Author: Steve Eddins Steve Eddins

Bard, I am not doing any active algorithm development in this area right now, and I have no plans to enhance this submission. You might want to take a look at Wolfgang Schwanghart's TopoToolbox: http://physiogeo.unibas.ch/topotoolbox/

23 Jun 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

I have submitted an update that corrects the problem with test cases in packages reported Jared Jacobs on June 16, 2010.

16 Jun 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

I've submitted new version 3.0.1 to fix the problem with handling TestCase subclasses inside packages. It should show up on the File Exchange in a day or two.

Here's my fix to the methodIsConstructor function inside TestSuite.m:

function result = methodIsConstructor(method)
method_name = method.Name;
if ~isempty(method.DefiningClass.ContainingPackage)
method_name = [method.DefiningClass.ContainingPackage.Name, '.', ...
method_name];
end
result = strcmp(method_name, method.DefiningClass.Name);
end

16 Jun 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Jared - sorry about that. I'll work on a fix right away.

09 Jun 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

William - Thanks. I'll make the fix.

27 Apr 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

David, In principle one could do this by subclassing TestRunMonitor (http://www.mathworks.com/matlabcentral/fx_files/22846/7/content/matlab_xunit/architecture/html/matlab_xunit_architecture.html#6) with something that spits out XML. I skimmed the information available at the link you provided, and it looks to me like the XML output described there is quite extensive and includes a number of elements that don't apply to MATLAB xUnit. Do you have more specific needs or requirements in mind? Drop me a note if so. My contact information is on my MATLAB Central author page.

25 Apr 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Nick, thanks for the suggestion. I'll investigate.

23 Apr 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Mike - no, that doesn't work right now. I've been asked about it a couple of times, and I intend to do it, but I just haven't had a chance yet.

02 Feb 2010 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Arthur,

Thanks for the report. I'll investigate and prepare an update.

04 Aug 2009 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Nick, thanks for the error report about assertElementsAlmostEqual and assertVectorsAlmostEqual. I uploaded a new version (2.0.1) today that fixes the problem.

04 Aug 2009 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Nick, the behavior with your setupdata function is a feature. See the doc page called "How to Write Tests That Share Common Set-Up Code."

http://www.mathworks.com/matlabcentral/fx_files/22846/6/content/matlab_xunit/doc/html/exTestFixtures.html

08 Jun 2009 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Ryan, I decided not to do the sprintf-style conversion specifiers in the assert functions, as least for now. My experience designing syntaxes for MATLAB and toolbox functions makes me shy away from a syntax design with an indefinite set of trailing arguments, as in sprintf. Such a syntax design makes it difficult to expand the syntax to support other options in the future. For now, you can just inline a call to sprintf directly in the call to the assertion functions.

06 May 2009 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Ryan and Guido, the Help Browser team has identified the problem and is trying to fix the problem for the next MATLAB release. In the meantime, you can try this workaround: Put the MTEST directory after the MATLAB directories in your path, instead of before them.

Ryan, thanks for the enhancement suggestion. I have received several good suggestions, and I plan to work on an MTEST update soon.

23 Apr 2009 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Hi again Guido,

The Help Browser team was able to reproduce the problem you reported, and they are investigating it. I don't know yet if there's a work-around I could apply to the MTEST doc files.

Steve

20 Apr 2009 MATLAB xUnit Test Framework MATLAB xUnit is a unit test framework for MATLAB code. Author: Steve Eddins Steve Eddins

Hi Guido,

I have not been able to reproduce the problem using R2009a on my 32-bit WinXP SP3 machine.

Would you please double-check your MATLAB version? I believe the released version was 7.8.0.347, not 7.8.0.324 as you reported.

Thanks,

Steve

Contact us