quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

Use of QuarkusMainTest together with QuarkusTestResource #20672

Closed tmohme closed 3 years ago

tmohme commented 3 years ago

Describe the bug

I'm trying to test a CLI app together with a database. For this, I created a simple test in a class annotated with QuarkusMainTest and also QuarkusTestResource. Unfortunately, in this combination the specified QuarkusTestResource is ignored.

Expected behavior

The QuarkusTestResource annotation should be respected. Interestingly, when using QuarkusTest instead of QuarkusMainTest, the test QuarkusTestResource is respected.

Actual behavior

The QuarkusTestResource annotation is ignored. Somehow, Quarkus figures out a PostgreSQL database is required and starts a Testcontainer with a PostgreSQL DB, but it is not the one specified/configured by the resource class!

How to Reproduce?

  1. unpack reproducer.zip

  2. run ./mvnw clean test => The text "***starting***}" does not appear in the test-log. => Also, you will see in the log that postgres:13.2 gets started.

  3. Replace the QuarkusMainTest annotation with QuarkusTest and run the test again.
    => The text "***starting***" does appear in the test-log. => Also, you will see in the log that postgres:14 gets started.

Output of uname -a or ver

Darwin My-iMac.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "11.0.11" 2021-04-20 LTS OpenJDK Runtime Environment Zulu11.48+21-CA (build 11.0.11+9-LTS) OpenJDK 64-Bit Server VM Zulu11.48+21-CA (build 11.0.11+9-LTS, mixed mode)

GraalVM version (if different from Java)

./.

Quarkus version or git rev

2.3.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)

Additional information

No response

geoand commented 3 years ago

@stuartwdouglas I assume this was not intentional, right?

stuartwdouglas commented 3 years ago

The linked PR should fix it, but note that you will explicitly have to disable Dev Services (quarkus.devservices.enabled=false) otherwise you will get two datasources. This is due to a mismatch in the lifecycle of dev services and QuarkusTestResource that we can't really do much about (in general we recommend dev services instead of QuarkusTestResource).