setup for DevNexus workshop – BDD with Spock and JUnit 5

Burk Hufnagel and Jeanne Boyarsky will be presenting a full day workshop entitled “Behavior Driven Development with Spock / What’s new with JUnit 5“. at DevNexus this year. Attendees will use their laptops.

If you run into any trouble setting up for the lab, you can post a comment on this blog post or start a thread in the Testing or IDEs forum at CodeRanch.

Here’s what needs to be installed:

Java

The workshop uses Java 8. If you have Java 9 installed, please ensure it is not the default:

  • Windows/Linux: Update your path
  • Mac: mv /Library/Java/JavaVirtualMachines/java 9/Info.plist /Library/Java/JavaVirtualMachines/java 9/Info.plist.disabled

Validation: run java –version at the command line and ensure it prints out a Java 8 version.

Eclipse (recommended)

You can use the IDE of your choice or none at all. We will be able to answer all questions about Eclipse and the command line. If you choose IntelliJ (2017.2.1 or later), please be sure you are comfortable navigating, running tests and running builds in it.

  1. Download and install Eclipse Oxygen. If you already have Eclipse Oxygen, check the splash screen says it is the December version. If not, please download the latest Eclipse Oxygen.
  2. Help > Eclipse Marketplace Install the STS (Spring Tool Suite) plugin

Validation:

  1. Try to create a new empty Gradle project:
  2. File > New > Other > Gradle Project
  3. Give the project a name and finish
  4. Wait a minute or two for the project to be created
  5. File > New > JUnit Test Case
  6. Confirm you have a radio button called “New JUnit Jupiter test”
  7. Click cancel to exist the wizard
  8. File > New > Other > Spring > Spring Bean Definition
  9. Click cancel to exit the wizard
  10. Success, you are ready for the workshop!

Optional: Gradle

We will be using Gradle as the build tool. While the projects will contain a Gradle command line, you are welcome to use your own Gradle install.

Optional: Git

One of the steps will be to pull code from git. If you have a git command line (or git bash), this is a one line operation. If not, you’ll be able to download a zip file from github so this isn’t a hard requirement.

 

eclipse oxygen (4.7.1.a) for the mac for the third time

I had downloaded Eclipse Oxygen when it came out in June. Then I downloaded the September version for early Java 9 support along with the JUnit 5 add on for the JavaOne Hands On Lab I delivered. This required downloading the Eclipse plugin. I’m giving a similar/longer JUnit 5 lab at DevNexus this month. It makes sense to start with a clean version for students to install. Therefore I decided to install Eclipse Oxygen for the third time.

This time I downloaded the December release of Oxygen (4.7.1a). It includes JUnit 5 and Java 9 support.

Installing

I downloaded Eclipse and chose “Eclipse IDE for Java Developers” from the wizard.

Opening Eclipse, I confirmed that I was using the December 2017 package.

Installing the plugins

The significant plugins I chose to re-install are listed in this table. eGit, Buildship (for Gradle), m2e (Maven) and I think EclEmma were already installed without me doing anything.

Plugin Purpose
Eclipse Tomcat Plugin One click launch for recent versions of Tomcat. Both are listed as being successors to Sysdeo. While both seem fine, I went with the “Eclipse Tomcat Plugin” that I had before updating Oxygen.
SonarLint  I use SonarLint daily to look for errors in my code.
Subclipse I got errors installing Subversive last time and switched to Subclipse.
Eclipse Memory Analyzer For finding memory leaks. Unlike last year with Neon, it installed cleanly from Eclipse Marketplace.
Freemarker IDE Freemarker syntax highlighting and macro assistance.

 

Pydev Python plugin/perspective
Contrast To spot potential security issues. See my impressions of the Contrast plugin.
Bytecode Outline I’ve been looking at bytecode a good fit for the book to make sure I understand why things are happening. This plugin makes it easy. I first tried Bytecode Visualizer but install failed. (The website says there were 25 failed installs with the same dependency problem in the last 7 days). After installing Bytecode Outline, I realized this was the one I had installed for Luna anyway.
Pitclipse For mutation testing coverage

 

JavaOne – JUnit 5 BOF

“JUnit 5 BOF”

Speaker: Sam Brannen

For more blog posts from JavaOne, see the table of contents


Sam invited us other JUnit presenters at JavaOne to sit on stage with him as a panel. Which was cool. I ot to sit on stage in a Moscone West room!

Sam reviewed/completed from his session earlier today

  • Tests package private
  • Create strings for message in lambda if have on where slow
  • assert timeout
  • Eclipse releases non beta support next week
  • assert all
  • nested tests – good for BDD style so can read as outline/steps with indentation in test report. there’s also an example of the bowling game where the indentation and display names make it easier to follow the output
  • Repeated tests
  • Parameterized tests – values, csv and method sources. Someone wrote an extension for a json source
  • dynamic tests – use lambdas
  • For future releases of JUnit – scenario tests (like in TestNG) where don’t do later steps if earlier fail, test ordering (good for integration tests), parallel execution, option to have new or existing instance for multiple tests, executing in user defined theads, declaration test suites for junit platform (declare which tests to run based on annotations)
  • The name JUnit sucks because we write many types of tests
  • Order of tests is based on hash code of method name since JUnit 4.8. Jupiter would give options.
  • Eclipse only provides a few options to customize which tests run. Maven/Gradle have more
  • Spring 5 – released last week, supports existing features and constructor/method injection, conditional test execution using SpEL expressions (can disable test by OS or date or other conditions – @EnabledIf/@DisabledIf, @ExtendWith(SpringExtension.class) so can use with Mockito or other former runner. @SpringJUnitConfig/@SpringJUnitWebConfig combines spring extension with spring config

Steve Moyer plugged the side project JUnit Pioneer for ope source extensions. Will be building extensions for the JUnit 4 rules that don’t have JUnit 5 equivalents. Also serves as an incubator for JUnit core. Has beta plugin for pi test.

JUnit 5 samples repo shows how to start with Gradle/Maven. Surefire team had non backward compatible change which is why need 2.19 to work. Later version of JUnit 5 will require 2.21+ to avoid this issue.

Starting surefire 2.20, recommend *Tests instead of *Test.