Functional testing Java-EE applications with TestEE.fi – 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, TestEE.fi offers JUnit 5 integration since day one! And of course, it’s just as easy to functional test your Java-EE applications with TestEE.fi 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:

<dependencies>
	<dependency>
		<groupId>fi.testee</groupId>
		<artifactId>testeefi-junit5-all</artifactId>
		<version>0.6.1</version>
		<scope>test</scope>
	</dependency>
	
	<!-- TestEE.fi uses slf4j, so add logback as logging implementation -->
	<dependency>
		<groupId>ch.qos.logback</groupId>
		<artifactId>logback-classic</artifactId>
		<version>1.1.7</version>
		<scope>test</scope>
	</dependency>
</dependencies>
Maven setup for using TestEE.fi 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 TestEE.fi with JUnit 52

Writing a TestEE.fi 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 TestEE.fi extension:

@ExtendWith(TestEEfi.class)
public class MyTest {
	@Mock
	private ExternalSystemBean externalSystem;
	@Inject
	private FacadeBean facadeToTest;
	
	@Test
	public void runTest() {
		// Your test code
	}
}
A minimalistic JUnit 5 example

Conclusion

Using TestEE.fi 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, TestEE.fi is ready it.

A working example project an be found here.

If you want to know more about advanced testing with TestEE.fi, 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 *