Is it possible to programmatically generate JUnit test cases and suites?

Have you considered using FIT for that?

You seem to have the tables already ready, and "business rules" sounds like "business people write them using excel".

FIT is a system for checking tests based on tables with input->expected output mappings, and a open source java library for running those tests is available.


We tried FIT and decided to go with Concordion. The main advantages of this library are:

  • the tests can be checked in alongside the code base (into a Subversion repository, for example)
  • they are executed by a standard JUnit runner

Within JUnit 4 you will want to look at the Parameterized runner. It was created for the purpose you describe (data driven tests). It won't organize them into suites however.

In Junit 3 you can create TestSuites and Tests programatically. The answer is in Junit Recipes, which I can expand if you need it (remember that JUnit 4 can run Junit 3 tests).