0

In Juint5 is this possible to add @EmbeddedKafka without spring-boot? Basically, we wanted to use EmbeddedKafka with spring-core in Juint5.

In the below example, RawKafka is able to start in Junit4.

https://github.com/bijukunjummen/sample-spring-kafka-producer-consumer/blob/master/sample-spring-kafka-producer/src/test/java/sample/producer/embed/EmbedKafkaTest.java

Is any chance we can do the same thing in Junit5 without SpringBootTest ???

Or any other option to create in-memory Kafka in Juint5?

Sounak Saha
  • 852
  • 1
  • 9
  • 21

1 Answers1

0

Yes. @EmbeddedKafka can be used with normal spring test and even a plain junit5 test.

For example, in case of spring test (i.e not @SpringBootTest) you can do :

@EmbeddedKafka
@ExtendWith(SpringExtension.class)
public class KafkaTest {

   @Autowired
   private EmbeddedKafkaBroker broker;

   @Test
   void test(){
      //access EmbeddedKafkaBroker to do stuff.
   }
}

In case of pure junit5 test , you can do :

@EmbeddedKafka
public class KafkaTest {

   @Test
   void test(EmbeddedKafkaBroker broker){
      //access EmbeddedKafkaBroker to do stuff.
   }
}

Ken Chan
  • 84,777
  • 26
  • 143
  • 172