prog::testUnit – xUnit-style extensions to the MuPAD test framework
prog::testUnit provides xUnit-style extensions to the MuPAD test framework.
Details:
The purpose of this library is to support test-driven programming, and in general to help the developer analyzing quickly failing tests. To this end, it provides tools to run tests from the test suite from an interactive MuPAD session, typically within the debugger. Ultimately one would want to be able to run each tests or section of test individually, as in the xUnit world.
This library is designed to work as much as possible with a standard MuPAD test file. However it works best if the test file is designed with individual testing in mind and gives some extra hints to the framework.
Here is a typical test file for a domain tric::trac. Following the standard MuPAD package layout it would reside in the file "lib/TRIC/trac.tst".
export(prog::testUnit, Alias):
////////////////////////////////////////////////////////////
testinit("trac"):
// Global setup for all the tests
export(tric, Alias, trac):
export(combinat, Alias, partitions):
////////////////////////////////////////////////////////////
testfunc(tric::trac::f):
test(f(1), 2):
test(f(2), 2):
test(f(3), 2):
////////////////////////////////////////////////////////////
testfunc("tric::trac::f with option Bla"):
test(f(1, Bla), 2):
...
////////////////////////////////////////////////////////////
testfunc(tric::trac::g):
// extra setup for the tests in this section
...
test(g(1), 2):
...
// extra cleanup for the tests in this section
...
////////////////////////////////////////////////////////////
testexit():
prog::check(tric::trac, 3):
// Clean up common to all the tests
Note that this is perfectly compatible with the MuPAD standard test files: if the setup or tear_down functions are not defined, the code inside will be safely executed, and the function call ignored.
The goal of the library is to allow for the following:
// runs all the tests:
prog::testUnit::runTests(tric::trac);
// runs all the tests concerning f, while
// skipping the execution of all code in the setup,
// test, or tear_down calls of other sections:
prog::testUnit::runTests(tric::trac::f);
// runs only the tests in the section "tric::trac::f"
prog::testUnit::runTests("tric::trac::f");
// runs only the tests in the section "tric::trac::f with option Bla":
prog::testUnit::runTests("tric::trac::f with option Bla");
// runs the setup code required for section "tric::trac::g"
prog::testUnit::setupTest("tric::trac::g")
// execute some tests of this section manually
debug(g(1))
This is essentially compatible with standard MuPAD test files. Of course, there is no guarantee that running tests in individual sections will work. Same thing if there are interdependency between sections. Just use your common sense.
So far, running individual tests is not yet implemented. While running the tests, prog::test is temporarily modified so as not to trap errors; this is helpful to analyze those errors with the debugger.
runTests – runs the test
prog::testUnit::runTests(x)
Try to runs the tests corresponding to the MuPAD object x.
sourceDir – directory containing the source code
prog::testUnit::sourceDir(x)
Try to guess the directory containing the source code defining the MuPAD object x.
Changes in MuPAD 4.0
New Function.