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
https://www.eclipse.org/modeling/downloads/build-types.php

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

Updated my build using second bullet at: https://marketplace.eclipse.org/content/junit-5-support-oxygen#group-details
Notice the bit about clearing a checkbox regarding categories.
Update your Eclipse 4.7 build using this update site: http://download.eclipse.org/eclipse/updates/4.7-U-builds.
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/STS.app/Contents/MacOS/eclipse"  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 https://marketplace.eclipse.org/content/junit-5-support-oxygen#group-details 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.

By the way: regarding TDD

Check out the Agile Thoughts podcast.  This podcast gets the Confessions Of An Agile Coach's endorsement (naturally, since the same people produce it) of quality materials for developers and teams trying to get coding done in a way that avoids dealing with legacy issues such as bugs and hard to maintain code.  Agile Thoughts has a lot of great TDD conceptual content along with a radio drama about the difficulties to getting a TDD initiative started.  Click the podcast cover below or here for more information.


Agile Thoughts podcast

References

A Look at JUnit 5’s Core Features & New Testing Functionality https://stackify.com/junit-5/
JDT UI/JUnit 5 https://wiki.eclipse.org/JDT_UI/JUnit_5