My scenario is the following I want to add a @QuarkusTestResource(DBResource.class) on my integrational tests which require a i.e. Database so I want to fire up the DB in the DBResource QuarkusTestResourceLifecycleManager while leveraging the testcontainers library similar to what people try to achieve here: https://github.com/quarkusio/quarkus/issues/8097
Describe the bug
I noticed when adding the @QuarkusTestResource(DBResource.class) to my integrational tests the DBResource is also invoked during my regular quarkus tests which do not need to fire up a Database via testcontainers.
I created a small reproducer: https://github.com/ineednousername/quarkus-reproducers
This reproducer is without testcontainers which shows the same behaviour. During my regular test a config property is set to "true" even though it should be always "false" (see application.properties)
But it is set to "true" since DBResource.java --> QuarkusTestResourceLifecycleManager is invoked on the test even though it is missing the @QuarkusTestResource annotiation.
@QuarkusTest
public class FruitTest {
On the integrational test everything works as expected see https://github.com/ineednousername/quarkus-reproducers/blob/master/src/test/java/org/example/FruitsResourceIT.java
Expected behavior
(DBResource) QuarkusTestResourceLifecycleManager should only be invoked on QuarkusTests that are annotated with @QuarkusTestResource(DBResource.class) e.g. only on FruitsResourceIT
Actual behavior
(DBResource) QuarkusTestResourceLifecycleManager is invoked on all tests even if they are not annotated with @QuarkusTestResource(DBResource.class) see: https://github.com/ineednousername/quarkus-reproducers/blob/master/src/test/java/org/example/FruitTest.java
To Reproduce
Steps to reproduce the behavior:
Configuration
https://github.com/ineednousername/quarkus-reproducers/blob/master/src/main/resources/application.properties
Environment (please complete the following information):
uname -a or ver:java -version:mvnw --version or gradlew --version):Additional context
(Add any other context about the problem here.)
Hi, I have the same issue here.
I've investigated just a little bit, here my stackstrace.
java.lang.RuntimeException
at org.kie.kogito.trusty.service.InfinispanServerTestResource.start(InfinispanServerTestResource.java:32)
at io.quarkus.test.common.TestResourceManager.start(TestResourceManager.java:33)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.test.junit.QuarkusTestExtension.doJavaStart(QuarkusTestExtension.java:138)
at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:269)
at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:292)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$7(ClassBasedTestDescriptor.java:359)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:359)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:189)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:78)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:132)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:142)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:117)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
My very quick workaround is to set an enviroment variable in the pom just for the integration tests and then check in the start method of the TestResource class if that property is set or not. In that way I'm able to skip the setup of the resources for the classes annotated with QuarkusTest only. But this is just a workaround for the time being :)
@r00ta thanks for the tip, I will do the same to at least prevent the test resource to do any work during non integrational quarkus tests.
When using @QuarkusTestResource, it's used for all Quarkus tests that don't specify a @TestProfile.
In Quarkus 1.7, you will have the ability to specify QuarkusTestResourceLifecycleManager per @TestProfile (the code has already been merged in master and you can see an example at: https://github.com/quarkusio/quarkus/blob/34200ce171aabd73a4d8c71fb1c87b3c3eab7a66/integration-tests/main/src/test/java/io/quarkus/it/main/GreetingProfileTestCase.java#L25 )
@geoand thank you, looking forward to 1.7 release :-)