Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a prototype of test fixtures, an extension point designed to replaced rules. The core class is a new
TestFixture
interface that can be implemented in users' tests or put in a common location to be shared by multiple tests.The
TestFixture
API was designed so that it could be supported by JUnit Vintage tests as well as JUnit Jupiter tests. In the first commit I show integration with Vintage tests. In the second commit, as a proof of concept, I updatedTestCase
to supportTestFixture
(I figured if JUnit Legacy tests could support them, anything could).Although designed as a possible replacement for rules, test fixtures are in some ways less powerful, but in other ways more powerful. A fixture can cause code to be executed 1) before a test (or suite), 2) after a test (or suite) and/or 3) between the successful completion of the test (or suite) and any tear down calls (
@After
,etc) have been called. Unlike rules, however, they cannot be used to cause a failing test to pass, or to run a test multiple times.Test fixtures are also easy to compose. Here is an example of a test fixture using another one:
Here's an example how one might might run two fixtures in order:
See the
TemporaryDirectory
class for an example fixture.As it happens, test fixtures are also easier to test than rules are. Note that
TemporaryDirectory
does not have any methods that were added only for testing purposes, but the tests inTemporaryDirectoryTest
have the same coverage.Note that this change is missing many tests, and would likely require some framework. I just wanted to send this as a concrete proposal for a simple but powerful extension point that can be supported by multiple styles of JUnit tests.