TwiP

"Tests with Parameters" allows you to simply add parameters to your JUnit test methods. TwiP calls such methods with all possible combinations of their parameters... or at least some reasonable subset of commonly failing values in the case of Integers, etc. You can further reduce these values with an assume expression in an annotation, e.g. ">= 0". This works for the primitive types (int, etc.), their Class wrappers (Integer, etc.), Enums and Strings. If you want your own types or a different set of values, you can define a static method or field and annotate the parameters of your test method(s), or you can annotate the field or method to inject the values by type.

By using TwiP you change the semantics of your tests from existence to for-all quantifiers, i.e. you specify "all ravens are black" instead of "Abraxas is black", "Toni is black", etc. This moves your tests closer to an executable specification, so TwiP is a very nice endorsement to BDD.

There are other ways to add parameters to your tests, most notably the JUnit Parameterized Runner. Especially the experimental Theories Runner that is built into JUnit since version 4.4 was a great inspiration for TwiP, but I think TwiP is much easier to grasp and handle than both of them, esp. for primitive types and enums. The theory behind TwiP is the same as that for the Theories runner.

For more information visit http://twip.sourceforge.net/