Pre-defined tests

This library mainly contains interfaces that each test one small aspect of a class or interface, often a single method. This is done for two reasons:

  • It allows testing only those methods that have been overridden / implemented. For instance, when testing a class that extends AbstractList, it's not necessary to test methods like subList if the class doesn't override them.
  • It allows nesting tests using @Nested. However, it's not required to do so.

To add tests to a class, simply implement the appropriate interface. All tests in the interface will then be added to the test class.

Collections framework

Package com.github.robtimus.junit.support.test.collections contains tests for the following interfaces in the Collections Framework:

For Collection, Iterator, List, ListIterator, Map, Map.Entry and Set there are also tests for unmodifiable versions of these interfaces. By implementing regular (modifiable) test interfaces for one set of operations and unmodifiable test interfaces for another set, it's easy to test implementations that support some operations but not others.

Examples

I/O

Package com.github.robtimus.junit.support.test.io contains tests for input streams, output streams, readers and writers.

Examples

Method delegation

DelegateTests makes it relatively easy to test that objects delegate to objects of the same type.

Examples

Covariant return type

CovariantReturnTests makes it relatively easy to test that classes override all fluent methods (methods returning this) to change the return type. It's also possible to use a different return type to check

Examples

Disabling pre-defined tests

Sometimes it's necessary to disable a test, e.g. because it doesn't apply to the class to test. An example is testing a partial sub list of an empty list; the only sub list to return is the full list. To disable a test, simply override it and don't apply any JUnit annotation to the method; this will make JUnit ignore the test.