Bob's pick this week is MATLAB xUnit Test Framework by Steve Eddins.
Do you use MATLAB to develop algorithms? Does your code rely on functions created by others? What kind of testing do you do?
For many users the answer may be something like this. "I tried a problem where I knew the solution. Since the right answer
was returned, I trust it." For some, that may be good enough. For others, a more systematic and comprehensive approach may
I know customers in some industries need to follow a strict process, and automated test suites allow a battery of test cases
to be exercised. So for example when any changes need to be made, the tests can be repeated to ensure no inadvertent bugs
were introduced in your code while adding a new feature. Now think beyond your own code. Maybe you just received a new version
of your favorite third party toolbox. Your boss wants you to check it out before deploying across the organization. Maybe
your software compliance or certification procedures dictate that new releases of all computing platforms, including MATLAB,
must be qualified before you can upgrade. This is where automated testing pays dividends.
Steve's test harness delivers! The detailed documentation is well organized from getting started to advanced usage. To illustrate, I used xunit to test one of my submissions, round2. The function help includes some example problems.
ROUND2 rounds number to nearest multiple of arbitrary precision.
Z = ROUND2(X,Y) rounds X to nearest multiple of Y.
Example 1: round PI to 2 decimal places
Example 2: round PI to 4 decimal places
Example 3: round PI to 8-bit fraction
Examples 4-6: round PI to other multiples
See also ROUND.
Examples usually make excellent test cases. Turning them into test points was a simple matter of codifying function calls
to return actual values, and providing expected values for comparison.
1 function test_suite = test_round2
4 function testExample1
7 function testExample2
10 function testExample3
13 function testExample4
16 function testExample5
19 function testExample6
Note that I also specified tolerances where appropriate. Now, running this test suite is straightforward.
Starting test run with 6 test cases.
PASSED in 0.010 seconds.
You can also read his IEEE Computing in Science and Engineering journal article, Automated Software Testing for MATLAB for more background. That touches on many facets of testing such as choosing good test cases to ensure code coverage.
As one of the Quality Engineers that Steve mentioned, I found xunit both powerful and easy to use. Since learning some things about Agile and Test-Driven development processes I see xunit being useful from small projects to large. From first learning MATLAB as an EE student in 1985 until I left the world of
applied R&D to join The MathWorks in 2001, I wrote a lot of MATLAB code, and I used what I knew: quick and dirty development.
As an application engineer, like Brett and Jiro, I met customers in many industries, and saw a wide user spectrum from novice
nonprogrammers to seasoned CS experts. Having moved along that spectrum myself, I really appreciate how much the bar has been
lowered. With MATLAB and xunit automated testing is not just for specialists. Thanks, Steve!
In this day and age software can change rapidly. This is the new normal. Enhancements may be demanded. Some bug fixes can
break prior workarounds. Programs can be really complex and rely on code from many different programmers. Maybe a colleague
changes a network shared file. Programs that worked once upon a time can break someday. These are modern facts of life. Automated
testing provides regression insurance in a world of change. How prepared are you?