Made with by giki

OLD-Components-Design-Sketch

Contributed by schauder

From the requirements I try to come up with a rough class/component structure that might enable the requested features.

TestSourceFinder

A TestSourceFinder finds TestSources. When JUnit gets invoked it can either use it’s default implementations or get additional implementations provided. This would allow for completely different creation of tests, like tests based on story files, webpages and what not.

DefaultTestSource

JUnit might/should provide default implementation (DefaultTestSource) that finds all TestSources in one or more directories, the current classpath or a filtered part of the classpath possibly filtered by some ANT-like expression (where ‘*’ stands for anything but a ‘.’ and ‘**’ stands for anything).

TestSource

A TestSource upon invocation will register tests for executions. I’d expect the following implementations to be provided by JUnit:

In order to allow execution of single tests, a test source should

  1. register itself, or a specification of itself together with the test

  2. register the TestSourceFinder from which it was created

This is to allow IDEs and similar tools to reexecute tests or test sets efficiently even when they don’t explicitly know from where these tests are coming.

Additionally the TestSource should be able to register tags and/or key-value pairs with each test, probably the information above should just be a special case of such tags or key-value pairs.

Test Extension Points

Proposal 1 - one extension point

Rules similar to what we have in JUnit4 should be applicable based on tags/key-value pairs and allow for execution of code before, after and instantiation of a test or a test set defined by a common tag/key-value pair.

Ideally Rules would be used to implement as much as possible of the core functionality. Especially parallel execution, ordering, setup/teardown and parameterized test should be handled by rules. This ensures that Rules are flexible enough to support a wide range of use cases.

In order to handle arbitrary tags, it must be possible to register Rules independent from TestSources.

Proposal 2 - MetaRule and StatementFactory

MetaRule

A MetaRule would allow a single object to decorate the Statement chain at a class level and method level. It should be easy to have the meta rule create an object that lives for the life cycle of the class or suite that it modifies (without having to store that object in an evil static field).

A test class can have many meta rules.

Use cases include:

StatementFactory

A MethodFactory would allow a single object to create one or more Statement instances that run a test.

A test class can have only one StatementFactory.

Use cases include:

Modifier

TestListener

A TestListener can get registered similar to Rules, but does not change the execution of tests. It just gets informed about events like: