Reputation: 1317
I'm trying to use Embedded kafka for my tests.I'm using spring boot and junit5 as follows
@SpringBootTest
@EmbeddedKafka
public class MyTest {
//Instead of the class rule approach I'm using
EmbeddedKafkaBroker embeddedKafka = new EmbeddedKafkaBroker(1,true,topics);
..
@Test
public void myTestCase() {
....
}
However,my tests fail with the No resolvable bootstrap urls given in bootstrap servers
I'm using a test profile too where on the yml file I've
bootstrap-servers :{spring.embedded.kafka.brokers}
Please help.
Upvotes: 3
Views: 6779
Reputation: 44970
@SpringBootTest
initializes the test Spring Boot application context before the test class instance is created and member fields are initialized. Because of that the @SpringBootApplication
doesn't see the EmbeddedKafkaBroker
as the field is initialized later.
Try following a working example from this answer:
@SpringBootTest
@EnableKafka
@EmbeddedKafka(
partitions = 1,
controlledShutdown = false,
brokerProperties = {
"listeners=PLAINTEXT://localhost:3333",
"port=3333"
})
public class KafkaConsumerTest {
@Autowired
KafkaEmbedded kafkaEmbeded;
}
Upvotes: 2