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
@RestateTest
Content copied to clipboard
class CounterTest {
// Annotate the service to bind
@BindService
Content copied to clipboard private final Counter counter = new Counter();
// Inject the client to send requests
@Test
Content copied to clipboard
void testGreet(@RestateClient
Content copied to clipboard Client ingressClient) {
var client = CounterClient.fromClient(ingressClient, "my-counter");
long response = client.get();
assertThat(response).isEqualTo(0L);
}
}
Content copied to clipboard
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 PER_CLASS automatically.
Use the annotations RestateClient, RestateURL and RestateAdminClient to interact with the deployed environment:
@Test
Content copied to clipboard
void initialCountIsZero(@RestateClient
Content copied to clipboard Client client) {
var client = CounterClient.fromClient(ingressClient, "my-counter");
// Use client as usual
long response = client.get();
assertThat(response).isEqualTo(0L);
}
Content copied to clipboard