I would like to create a hierarchy of TestSuites. However it appears that it is not possible to call a TestSuite from another TestSuite. So before I go and reinvent the wheel, I thought I would see how others have done (or would) accomplish this.

Details of what I am trying to accomplish

I have grouped packages (and their tests) that perform like functionality by directory. For illustrative purposes lets say I have three subdirectories: importers, manipulators, and processes. I have a TestSuite in each subdirectory named TestAll.mt . I also have one in the top level directory called TestAll.mt that I would like to have call the TestAll.mt in the three subdirectories.

I would like to be able to run the test suites at both the subdirectory and top levels. Running the test suite at the subdirectory level would only run the particular subset of tests, while running the test suite at the top level would run the test suites in all the subdirectories.

I would like to avoid having to add an entry for a particular test to both the subdirectory and top level test suites.

A bonus would be if the top level test suite auto discovered the test suites in the subdirectories (not having to specify the subdirectories in the root test suite), but that is not crucial.


Attempt #1 -- Make a list of .mt files in each of the sub TestAll.mt s. If the top level TestAll.mt is called, the sub levels' lists would be appended to the top level's list and then that list would be supplied to TestSuite. If a sub level's TestAll.mt is called, its list would be supplied as the argument to TestSuite.

Result: Failure

From Workbench, adding any expression to a .mt that contains TestSuite appears to cause none of the tests to run.


From a notebook, TestSuite shows up in command completion, but does not show up in the MUnit package usage info. Executing the following:


Results in:

TestSuite[{"/pathToTests/Test1.mt", "/pathToTests/Test2.mt"}]

Searched the MUnit package files for TestSuite, no hits.

cd "/Applications/Wolfram Workbench.app/configuration/org.eclipse.osgi/bundles/214/1/.cp/MathematicaSourceVersioned/Head/MUnit"
find . -name "*.m" -print -exec grep TestSuite {} \;

Attempt #2 -- Roll my own TestSuite ...

  • $\begingroup$ @magma Not sure why you added workbench. The solution should work either way. Eventually I was hoping to fold this into part of automated post source code commit process. $\endgroup$
    – mmorris
    Mar 7, 2012 at 9:12
  • $\begingroup$ Workbench has unit testing facilities, so I thought that you would use it to do your testing. Is this not so? And even if not, wouldn't your question be relevant/interesting to a Workbench user? Anyway, adding a tag has never armed anybody. $\endgroup$
    – magma
    Mar 8, 2012 at 1:41
  • $\begingroup$ @magma Adding the tag was not an issue. Actually, before I created the munit tag I had it tagged as workbench, only for a lack of a better tag. I reverted your edit, because I felt adding "Workbench" to the question title and body changed my question to only pertain to Workbench, instead of both notebooks and Workbench. $\endgroup$
    – mmorris
    Mar 9, 2012 at 1:46
  • $\begingroup$ I am not very familiar with unit testing. I thought it could only be done (easily) with workbench. From what I see, the only answer you got so far relates to workbench. I added the workbench tag to help future searches (certainly mines) to retrieve this question and answer (which relates to workbench for sure). Would you mind if I/you/we add the workbench tag to this thread? $\endgroup$
    – magma
    Mar 9, 2012 at 10:01
  • $\begingroup$ I just found a list of unit testing software in wikipedia: en.wikipedia.org/wiki/List_of_unit_testing_frameworks Mathematica is conspicuously absent. Somebody knowledgeable in this matter should do something about it. $\endgroup$
    – magma
    Mar 9, 2012 at 10:16

1 Answer 1


Here are two ideas:

  1. In the documentation there is an example of how to write a test suite, a collection of tests.
  2. Try to load the MUnit package (I think it is somewhere in Workbench) from Mathematica. Then define

    runTests[] := Map[TestRun, FileNames["path/to/testFiles/*.mt"]]

and call

  • $\begingroup$ Either I am missing something in idea 1 -or- you may have missed something in my question. I tried creating a TestSuite that called other .mt files that were TestSuites which were collection of tests. That did not work. $\endgroup$
    – mmorris
    Mar 7, 2012 at 9:01
  • $\begingroup$ For Idea #2 see $\endgroup$
    – mmorris
    Mar 7, 2012 at 9:19
  • $\begingroup$ Yes, indeed, I did not get that you wanted yet another layer of TestSuits. I have never tried/needed this. You could write a a fucntion that would generate one TestSuite that contains all Tests from the sub directories. $\endgroup$
    – user21
    Mar 7, 2012 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.