Annotation Type VertxTest
@Target(TYPE)
@Retention(RUNTIME)
@ExtendWith(VertxExtension.class)
@Inherited
public @interface VertxTest
Annotation for JUnit 5 test classes that use Vert.x. Applying this annotation registers the
VertxExtension, which manages Vertx and
VertxTestContext instances for parameter injection.
By default, any Vertx instance created by the extension and injected into test
methods or constructors is instrumented: its
exception handler is set to
VertxTestContext.failNow(Throwable), so any unhandled exception occurring inside
Vert.x (e.g. in a handler) automatically fails the test. This is
equivalent to wrapping handler code in VertxTestContext.verify(VertxTestContext.ExecutionBlock), which catches
exceptions and calls failNow as well. Instrumentation saves you from having to
wrap every callback with verify; you can disable it by setting
instrumentVertx() to false.
This annotation is @Inherited, so subclasses of an annotated test class
are also treated as Vert.x tests.
Usage example:
@VertxTest
class MyTest {
@Test
void myTest(Vertx vertx, VertxTestContext ctx) {
// No need to wrap with ctx.verify(), unhandled exceptions
// in Vert.x handlers will automatically fail the test.
}
}
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether to instrument theVertxinstance by setting its exception handler toVertxTestContext.failNow(Throwable), so that unhandled exceptions automatically fail the test.
-
Element Details
-
instrumentVertx
boolean instrumentVertxWhether to instrument theVertxinstance by setting its exception handler toVertxTestContext.failNow(Throwable), so that unhandled exceptions automatically fail the test. Defaults totrue.- Returns:
trueto instrument theVertxinstance,falseotherwise
- Default:
true
-