Java Magazine, May/June 2016
ORACLE COM JAVAMAGAZINE MAY JUNE 2016 38 testing JUnit the widely used Java unit testing framework has just seen the first alpha release of version 5 after 10 years on version 4 JUnit 5 consists of a revamped codebase with a modular architecture a new set of annotations an extensible model for third party library integration and the ability to use lambda expressions in assertions The predecessor of JUnit 5 was the JUnit Lambda project which sowed the first ideas for the next generation of unit testing and was crowdfunded until October 2015 Through the years JUnit has captured the essence of what a unit testing framework should be However its core mostly stayed intact which made it dificult for it to evolve This new version is a complete rewrite of the whole product that aims to provide a suficient and stable API for running and reporting tests Implementing unit tests with JUnit 5 requires Java 8 at a minimum but it can run tests on code written for earlier versions of Java In this article I describe the principal features of this early release of JUnit 5 illustrating them with detailed examples All the code in this article is based on JUnit version 500 ALPHA which was released in February 2016 The complete source code for the examples in this article is available at the Java Magazine download area The JUnit team is planning to ship a release candidate of the framework in the third quarter of 2016 Milestone 1 is one of the last steps before JUnit 5 oficially ships This will surely be one of the most consequential releases ever in the Java ecosystem Configuring Tools to Use JUnit 5 JUnit 5 dependency definitions are available for both Maven and Gradle For this article I used Maven and its dependency definition for the JUnit 5 API The following shows the Maven inclusion of JUnit 5 dependency groupId org junit groupId artifactId junit5 api artifactId version 500 ALPHA version scope test scope dependency JUnit 5 now consists of multiple modules including the junit5 api module which provides a transitive dependency and opentest4j which is named after the Open Test Alliance for the JVM project Its aim is to provide a minimal common foundation for testing libraries IDEs and other tools such as TestNG Hamcrest Spock Eclipse Gradle Maven and many others In addition JUnit 5 has the following modules junit5 api an API module that contains classes for implementing tests junit4 engine a JUnit 4 engine implementation It locates and runs JUnit 4 based tests junit5 engine a JUnit 5 engine implementation module It locates and runs JUnit 5 based tests junit engine api an abstraction API module for testing engines It provides an extensible mechanism with MERT ÇALIS KAN JUnit 5 A First Look The long awaited release of JUnit 5 is a complete redesign with many useful additions
You must have JavaScript enabled to view digital editions.