My usecase is that we have two custom test-profiles “test-fast” and “test-slow”, which we use to have local testing be faster than CI/CD pipeline testing. We also want “test-slow” to not require a docker environment.
Now we have a few tests that test against a kafka broker. For this, we basically have this config:
# Pipeline sets -Dquarkus.test.profile=test,test-slow
quarkus.test.profile=test,test-fast
%test-fast.quarkus.kafka.devservices.enabled=false
%test-slow.quarkus.kafka.devservices.enabled=true
The respective kafka test would fail at runtime because there’s no kafka broker, so we added this:
@BeforeAll
static void beforeAll() {
assumeTrue(ConfigUtils.getProfiles().contains("test-slow"), "Kafka is only set-up in the slow test profile");
}
This works fine. The test is skipped in test-fast
and executed in test-slow
.
However, we now want to add the Kafka Companion to the test to be able to check the actual received kafka messages. To do this, we need to annotate the test with @QuarkusTestResource(KafkaCompanionResource.class)
. This launches a kafka instance, as described in the docs:
If the Kafka Dev Service is available during tests, KafkaCompanionResource uses the created Kafka broker, otherwise it creates a Kafka broker using Strimzi Test Container.
But we do not want a kafka broker to be started in the test-fast
profile! Is there a way to have the @QuarkusTestResource(KafkaCompanionResource.class)
only actually boot up a kafka when in a specific test profile?