Java Magazine, Nov/Dec 2016
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2016 23 junit 5 logManager org apache logging log4j jul LogManager Console integration The ConsoleLauncher command line application enables you to run the JUnit Platform directly from the console The launcher can be executed with the Java command shown in Listing 8 Building the classpath with the needed JAR files is a prerequisite so ensure that you have the correct version of the artifacts Listing 8 java cp path to junit platform console 100 M2 jar path to jopt simple 502 jar path to junit platform commons 100 M2 jar path to junit platform launcher 100 M2 jar path to junit platform engine 100 M2 jar path to junit jupiter engine 500 M2 jar path to junit jupiter api 500 M2 jar path to opentest4j 100 M1 jar org junit platform console ConsoleLauncher a The classpath should be entered as a single line Ed The a argument specifies that all tests should be run The n argument can also be used to run only test classes whose fully qualified names match a regular expression Several other options are available although according to the documentation they are subject to change IDE integration Java IDEs on the market are quickly evolving to provide robust support for running JUnit 5 tests At the time of this writing IntelliJ IDEA handles JUnit 5 tests with its current release and creates a tree for tests by providing support for both Jupiter and Vintage packages Sample output for testing a series of stack operations is shown in Figure 2 The test class contains the new @ Nested annotation on test classes which enables creating hierarchies of tests which are correctly represented in this figure Eclipse Neon and NetBeans 81 also support executing JUnit 5 tests with the help of the JUnitPlatform runner which makes it possible to run JUnit 5 tests on the JUnit 4 platform within the IDE Backward Compatibility with Vintage Mode With the help of the JUnit Platform class which is an implementation of JUnit 4 s Runner its possible to execute JUnit Jupiter based test classes on JUnit 4 The junitplatform runner module contains the needed JUnitPlatform class and it should be defined with the Figure 2 Output from IntelliJ for nested tests
You must have JavaScript enabled to view digital editions.