Hoverfly-Java is now JUnit 5 ready

Special thanks to Alex Soto from Red Hat, we have finally released Hoverfly Java JUnit5 0.9.0. It is available from Maven Central.

This new package takes advantage of the new JUnit 5 Extension model to provide finer control of Hoverfly throughout JUnit 5 testing life cycles. The dependency injection feature gives you the ability to configure Hoverfly in a per-test basis.

To get started, simply add the dependency to your build.gradle:

testCompile "io.specto:hoverfly-java-junit5:0.9.0"

TK More setup guide for Hoverfly and JUnit 5 can be found here.

Then register HoverflyExtension in your test class and you are good to go:

@DisplayName("An awesome test case with 🐝")
@ExtendWith(HoverflyExtension.class)
class MyTests {
// ...
}

This also applies to your nested test classes.

You can use the @HoverflySimulate @HoverflyCapture or @HoverflyCore annotations to customise the behavior of Hoverfly as well. An example of a common use case is to provide a global simulation source and enable capturing if the source is not available.

@HoverflySimulate(source = @Source(value = "missing-simulation.json", type = SourceType.DEFAULT_PATH),
enableAutoCapture = true)
@ExtendWith(HoverflyExtension.class)
class CaptureIfSimulationSourceNotPresentTests {
// ...
}

You can find full documentation here.

Please check out the project on GitHub. Contributions are welcome!