The Holy Java

Building the right thing, building it right, fast

Link: Advanced Usage of JUnit Theories, Multiple DataPoints, and ParameterSuppliers

Posted by Jakub Holý on September 16, 2011

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!

Sorry, the comment form is closed at this time.

%d bloggers like this: