Annotation Interface MicroserviceTest
Microservice (config + lifecycle +
embedded Jetty server) for the annotated JUnit 5 test class — the standalone-microservice analog of
Spring's @SpringBootTest.
@MicroserviceTest is a single, server-agnostic meta-annotation: it composes
@ExtendWith(MicroserviceExtension) plus a @Tag("microservice") marker.
The extension builds the microservice on an OS-assigned ephemeral port before the test class runs, and
stop()s it afterward (releasing the port and
firing @PreDestroy hooks).
Specifying the system under test
The SUT is declared explicitly (no classpath scanning), two complementary ways:
configurations()— one or more@Configurationclasses whose@Bean Servletmethods are auto-mounted by the microservice (the common case).- A
staticmethod on the test class returning aMicroservice.Builder— for full control over the builder. Discovered by name "microserviceBuilder" (override viabuilderMethod()). Configurations fromconfigurations()are appended to whatever the supplier returns.
In both cases the extension additionally installs an EphemeralJettyServerConfig (binding a Jetty
Server to port 0) and JettyConfiguration, so tests only contribute their resources.
Mock-bean injection
Declare collaborators to substitute with the existing @TestBean
(the @MockBean analog) — no parallel injection annotation. By default these are installed via
Mode INJECT (through Microservice.Builder.overridingBeanStore(...)) before boot, so the
service sees them from startup. @TestBean(mode = Mode.OVERLAY) pushes/pops against the already-booted
instance instead.
What gets injected into tests
Test methods (and lifecycle methods) may declare parameters resolved by the extension:
RestClient (bound to the booted server's root URL — the
primary convenience), Microservice, the
WritableBeanStore, and the bound port (as int
/ Integer). The same TestBeanStore parameter the underlying
JuneauBeanStoreExtension resolves is available too.
When to use this vs. MockRestClient
Use @MicroserviceTest for a genuine full-microservice integration test — real server, real
connectors, real lifecycle, over HTTP. For an in-JVM test of a single @Rest resource (no server, no
sockets), use MockRestClient directly; the two paths are intentionally distinct.
Example:
See Also:
- Since:
- 10.0.0
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionName of an optionalstaticmethod on the test class returning aMicroservice.Builderto seed the boot.Class<?>[]The@Configurationclasses whose@Bean Servletmethods the microservice auto-mounts.
-
Element Details
-
configurations
Class<?>[] configurationsThe@Configurationclasses whose@Bean Servletmethods the microservice auto-mounts.Appended after any builder produced by a
builderMethod()supplier, and before the framework'sEphemeralJettyServerConfig+JettyConfiguration.- Returns:
- The configuration classes. Empty by default (rely on a
builderMethod()supplier).
- Default:
- {}
-
builderMethod
Name of an optionalstaticmethod on the test class returning aMicroservice.Builderto seed the boot.The method must be
static, take no arguments, and return aMicroservice.Builder. When absent, a freshMicroservice.create()builder is used.configurations()are appended either way.- Returns:
- The supplier method name. Defaults to "microserviceBuilder".
- Default:
- "microserviceBuilder"
-