There are couple of annotations @UseKafka @UseTemporal @WireMockStubFor @DBRider for component tests, what are these annotations used for and how do we use them?

  • @UseKafka it start Kafka container only once and expose environment variable KAFKA_URL, use it when you write component test with Kafka

  • @UseTemporal it starts temporalite container and expose environment variable TEMPORAL_URL , use it when you write component test with Temporal

  • @WireMockStubFor(service = "thought-machine", exposedUrl = "TM_URL") , it start wiremock server to mock external service

  • @DBRider this annotation is used for initializing database and verifying database changes

Note: @UseKafka @UseTemporal @WireMockStubFor must be placed before @MicronautTest , otherwise Micronaut will not aware of the environment variables. And @DBRider must be placed after @MicronautTest since it use the datasource(connection) created by Micronaut.

A example test involves Temoral, Kafka and ThoughtMachine, the annotations should have order like below.

@UseTemporal
@UseKafka
@WireMockStubFor(service = "thought-machine", exposedUrl = "TM_URL")
@MicronautTest
@DBRider

Attachments: