Package dev.restate.sdk.testing
Annotation Interface RestateTest
@Target(TYPE)
@Retention(RUNTIME)
@Documented
@Inherited
@ExtendWith(RestateExtension.class)
@TestInstance(PER_CLASS)
public @interface RestateTest
Annotation to enable the Restate extension for JUnit 5. The annotation will bootstrap a Restate
environment using TestContainers, and will automatically register all services field of the class
annotated with
BindService.
Example:
// Annotate the class as RestateTest to start a Restate environment@RestateTestclass CounterTest { // Annotate the service to bind@BindServiceprivate final Counter counter = new Counter(); // Inject the client to send requests@Testvoid testGreet(@RestateClientClient ingressClient) { var client = CounterClient.fromClient(ingressClient, "my-counter"); long response = client.get(); assertThat(response).isEqualTo(0L); } }
The runner will deploy the services locally, execute Restate as container using Testcontainers, and register the services.
This extension is scoped per test class, meaning that the restate runner will be shared among
test methods. Because of this behaviour, the extension sets the TestInstance as TestInstance.Lifecycle.PER_CLASS automatically.
Use the annotations RestateClient, RestateURL and RestateAdminClient
to interact with the deployed environment:
@Testvoid initialCountIsZero(@RestateClientClient client) { var client = CounterClient.fromClient(ingressClient, "my-counter"); // Use client as usual long response = client.get(); assertThat(response).isEqualTo(0L); }
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionRestate container image to useString[]Environment variables in form key=value that should be added to the deployed Restate container.
-
Element Details