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.

Leave a Reply

Your email address will not be published. Required fields are marked *