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"
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 @HoverflySimulate
, @HoverflyCapture
or @HoverflyCore
annotations to customize 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 AutoCaptureSimulationTests {
// ...
}
You can find full documentation here.
Please check out the project on GitHub. Contributions are welcome!