Awesome Open Source
Awesome Open Source
Sponsorship

JUnit Extensions

Build Status Coverage Status Scrutinizer Javadoc Maven Central GitHub Release

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.

Documentation

Extensions

  • BenchmarkExtension: publishes test elapsed time to the console, by default, but also available via the EngineExecutionListener for 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.

Using JUnit-Extensions

The junit-extensions library is available on Maven Central:

Maven

<dependency>
    <groupId>io.github.glytching</groupId>
    <artifactId>junit-extensions</artifactId>
    <version>2.4.0</version>
    <scope>test</scope>
</dependency>

Gradle

testCompile 'io.github.glytching:junit-extensions:2.4.0'

Building JUnit-Extensions

$ 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.

License

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.###

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
java (29,705
testing (881
testing-tools (188
unit-testing (178
java-8 (117
junit (58
junit5 (17

Find Open Source By Browsing 7,000 Topics Across 59 Categories