Replacing Rules in JUnit 5

Rules have disappeared in the version 5 of the JUnit open source Java testing tools. The release 5 of JUnit is still in alpha status. In this article, Herrmann Rüdiger explores what it would take to transform existing rules to the new concept so that they could run natively on JUnit 5.

The article starts by explaining extensions, a new concept in JUnit. These extensions will be a good way to replace rules in JUnit and the blog post provides many code examples on how to achieve this goal. An interesting new features is that JUnit 5 provides a means to maintain state of extensions called Stores. Stores provide methods for extensions to save and retrieve data.

The conclusion of the blog post is “extensions are a decent and complete replacement for rules and friends in JUnit 4. And finally, using the new methods is fun and feels much more concise than the existing facilities. […] But note however, that as of this writing extensions are work in progress. The API is marked as experimental and may change without prior notice. Thus it might be a bit early to actually migrate your JUnit 4 helpers right now – unless you don’t mind to adjust your code to the potentially changing APIs.”

Read the full blog post on http://www.codeaffine.com/2016/04/06/replace-rules-in-junit5/