# MUnit creating a hierarchy of TestSuites

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.

## Update

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.

x=1;
TestSuite[
{
"Test1.mt",
"Test2.mt"
}
]


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

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


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 ...

-
@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. –  mmorris Mar 7 '12 at 9:12
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. –  magma Mar 8 '12 at 1:41
@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. –  mmorris Mar 9 '12 at 1:46
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? –  magma Mar 9 '12 at 10:01
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. –  magma Mar 9 '12 at 10:16

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

runTests[]

-
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. –  mmorris Mar 7 '12 at 9:01
For Idea #2 see –  mmorris Mar 7 '12 at 9:19
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. –  user21 Mar 7 '12 at 9:22