Sunday, January 7, 2018

Getting JUnit 5 into your Eclipse 4.7 Oxygen

Good Things Merit New Releases

Like Java, JUnit versions continue their onward march.  JUnit 5 is a more modularized version of JUnit 4, and supports and requires Java 8.

This is what entails a bundle of JUnit 5:

  • JUnit Platform – which enables launching testing frameworks on the JVM
  • JUnit Jupiter – which contains new features for writing tests in JUnit 5
  • JUnit Vintage – which provides support for running JUnit 3 and JUnit 4 tests on the JUnit 5 platform

My situation was more complicated as I am using Spring Tool Suite rather than straight Eclipse.

Updated my build using second bullet at:
Notice the bit about clearing a checkbox regarding categories.
Update your Eclipse 4.7 build using this update site:
In Eclipse, go to Help > Install New Software... and uncheck "Group items by category". Select "Eclipse SDK" from the list of items and proceed with the installation.
If you were using Spring STS3.9, your splash screen will change.  I couldn't use my usual MacOS icon and instead had to go to a terminal, navigate to my Spring install, and launch it with "./springsource/"  For me, my STS was stored in my home directory so navigate there and find a "springsource" directory.

It takes a few minutes for the IDE to move beyond the splash screen.  Be aware there may be a modal popup about updating your workspace hiding somewhere.
Don't be alarmed. It's still STS and as far as I could tell, everything was working with the exception of the Mac launch application and the splash screen change.

(XXX Did I really need to go and install JUnit 5 Support or was it already in that 4.7-U-builds bundle?)

After doing this, I was able to install "JUnit 5 Support for Oxygen" plugin by using STS to go to the marketplace, and then dragging the "install button" from and dropping it onto the marketplace.

And then:

 After rebooting, check that it was installed by going back to the Marketplace and selecting the installed filter.

Add a Junit Test case to your source and you'll see JUnit Jupiter below as one of the radio buttons.
(XXX At the beginning introduce the JUnit5 ecosystem: JUnit5, Jupiter, ....)

 Upon clicking finish you'll be asked about adding JUnit5 to your build path.

This is the template test case it inserted. Notice the org.junit.jupiter namespace. Let's run it and see if it fails.

Like you've always done with JUnit, you can select the project name or the single test case, then execute tests with the context menu.
 And you should see the below red bar since the test case template has a "fail()" statement.

A Look at JUnit 5’s Core Features & New Testing Functionality
JDT UI/JUnit 5