Earlier this week I posted an update to my MTEST unit test framework on the File Exchange. I wasn't completely happy with my assertion function for comparing floating-point numbers using a tolerance, so I added two new ones: assertElementsAlmostEqual and assertVectorsAlmostEqual. I also fixed a problem with the way mtest was scanning the current directory in order to find test files.
Last week someone asked me about integrating the MTEST doc in the MATLAB Help Browser, so I looked into that. It is possible, as it turns out. There's a detailed explanation of how to do that in the MATLAB Helper Browser documentation. See the section on Adding HTML Help Files for Your Own Toolbox. Using this explanation, I was able to have the MTEST documentation appear in the Help Browser. If you distribute your own MATLAB code for others you use, you might want to give this a try.
James—Yes, assertAlmostEqual has disappeared from the main documentation. That was intentional. The explanation is in the first paragraph of this post. I have the new floating-point comparison functions assertElementsAlmostEqual and assertVectorsAlmostEqual. I left assertAlmostEqual there to avoid making an incompatible change, but I would prefer that people use the new functions.
Ah, then I’ll change my test functions to not use assertAlmostEqual any more.
By the way, your post on MTEST and refactoring made me read through the books “Test-driven development” (Beck) and “Refactoring” (Fowler) plus try programming MATLAB in an object oriented way. I’m still assessing the advantages and disadvantages for my work, but the most obvious at the moment are:
- the code is more robust than I’m used to
- the development time is somewhat slower than I’m used to
James—That’s a lot of changes to try all at once! Test-driven development and object-oriented programming both take some getting used to. Some programmers find that development pace actually speeds up with test-driven development, because the fraction of time spent debugging goes way down. But that’s only after you have some experience with the technique, and only if you get in the habit of making code changes in small, rapid increments.
Leave a Reply
About
Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.
Is is just me, or has AssertAlmostEqual disappeared from the main documentation of mtest?
James—Yes, assertAlmostEqual has disappeared from the main documentation. That was intentional. The explanation is in the first paragraph of this post. I have the new floating-point comparison functions assertElementsAlmostEqual and assertVectorsAlmostEqual. I left assertAlmostEqual there to avoid making an incompatible change, but I would prefer that people use the new functions.
Ah, then I’ll change my test functions to not use assertAlmostEqual any more.
By the way, your post on MTEST and refactoring made me read through the books “Test-driven development” (Beck) and “Refactoring” (Fowler) plus try programming MATLAB in an object oriented way. I’m still assessing the advantages and disadvantages for my work, but the most obvious at the moment are:
- the code is more robust than I’m used to
- the development time is somewhat slower than I’m used to
James—That’s a lot of changes to try all at once! Test-driven development and object-oriented programming both take some getting used to. Some programmers find that development pace actually speeds up with test-driven development, because the fraction of time spent debugging goes way down. But that’s only after you have some experience with the technique, and only if you get in the habit of making code changes in small, rapid increments.