It is surprising how difficult it is to find documentation for some JUnit features such as Theories. May be they haven’t bothered to write it because it is still considered “experimental” (even though included in JUnit since 4.4). As usually we have to rely on Jens Schauder’s blog and I’d like to draw your attention to his post describing advanced usage of JUnit Theories including things like
- multi-argument @Theory methods (each argument’s value taken from a different set of data points thanks to their different data types),
- @TestedOn as an in-place values supplier, and
- use of org.junit.Assume.assumeThat,
- the use of parameter suppliers (create a marker interface annotated with @ParametersSuppliedBy(YourImplementation.class), create the implementation extending ParameterSupplier, and annotate your theory’s argument with the interface)
Thank you, Jens!