Functional testing Java-EE applications with – Part 6: JUnit 5

Good news Everyone!™ The number one testing framework in the Java ecosystem has moved a major step forward: JUnit 5 final is available since yesterday and brings lots of major improvements for the way you implement your test cases!

And of course, offers JUnit 5 integration since day one! And of course, it’s just as easy to functional test your Java-EE applications with as it was with JUnit 4.

Dependency management

Just make sure you’re using the testeefi-junit5-all dependency instead of the JUnit 4 version in your Maven dependencies:

	<!-- uses slf4j, so add logback as logging implementation -->
Maven setup for using with JUnit 5

In Gradle your dependencies would look like this:

dependencies {
	testCompile 'fi.testee:testeefi-junit5-all:0.6.1'
	testCompile 'ch.qos.logback:logback-classic:1.1.7'
Gradle setup for using with JUnit 52

Writing a extended test with JUnit 5

The JUnit 4 integration leveraged the concept of Runners where you could specify a custom Runner implementation using the @RunWith annotation. JUnit 5 abandons the concept of Runners and instead offers the option to add multiple Extensions to your test class using the @ExtendWith annotation.

So, remembering the minimal introductory example from Part 1, we can accomplish the same now by simply using the extension:

public class MyTest {
	private ExternalSystemBean externalSystem;
	private FacadeBean facadeToTest;
	public void runTest() {
		// Your test code
A minimalistic JUnit 5 example


Using with JUnit 5 is just as easy as it was with JUnit 4. Whether you are migrating an existing project to the new JUnit version (which does not come for free!) or setup a new Jave-EE project using the latest iteration of Java’s most famous test execution framework, is ready it.

A working example project an be found here.

If you want to know more about advanced testing with, be sure to check out the other posts of this series to get you up to speed quickly:

Leave a Reply

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