With thanks and appreciation to the authors of JUnit5.
There have been discussions amongst the JUnit community (see this and this) about providing official JUnit Jupiter Extensions for the most popular JUnit4 Rules. The upshot of these discussions seems to be enabling limited support for JUnit4 rules on JUnit5. For anyone who would rather move entirely to JUnit5, this library provides JUnit5 implementations of some of the commonly used JUnit4 rules.
BenchmarkExtension: publishes test elapsed time to the console, by default, but also available via the
EngineExecutionListenerfor customised reporting.
ExpectedExceptionExtension: allows you to run a test method with an expected exception and (optionally) exception message, delegating responsibility for making the assertion to the extension.
RandomBeansExtension: allows you to inject random instances of classes into your tests, useful when you need a class instance to test with but you don't care about its contents.
SystemPropertyExtension: allows you to set system properties before test execution and reverts these changes on test completion.
TemporaryFolderExtension: allows you to create temporary files and directories in your test, any such files or directories created in your tests are removed for you when the tests complete.
TestNameExtension: allows you to use the name of the currently executing test within your test cases.
WatcherExtension: logs test execution flow including entry, exit and elapsed time in milliseconds.
junit-extensions library is available on Maven Central:
<dependency> <groupId>io.github.glytching</groupId> <artifactId>junit-extensions</artifactId> <version>2.4.0</version> <scope>test</scope> </dependency>
$ git clone https://github.com/glytching/junit-extensions.git $ cd junit-extensions $ mvn clean install
This will compile and run all automated tests and install the library in your local Maven repository.
Note: the code is formatted using the Google Code Formatter.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.###