Allow certain features and extensions to be turned off while testing
See original GitHub issueI want to add some unit tests to my Quarkus maven project. I’m working on a multi-module project structured as:
- parent
-
- persistence (2 profiles [postgres, oracle])
-
- business (depends on persistence module)
-
- resource (depends on business module)
-
- deploy-rest (with quarkus maven plugin)
-
- deploy-lambda (with quarkus maven plugin)
The test is very simple (empty implementation) and is located in the business module.
@QuarkusTest
class CARootCreateControllerImplTest {
@Test
void handleRequest() {
}
}
When I try to execute my test, quarkus raises an error because agroal (from persistence dependency) needs the database configuration. First question: how can I run only unit tests (not integration) that don’t use the database but only mocks?
However, I have tried to solve the problem by adding a test/resource/application.properties fake configuration and agroal this time found it, raising another error. This second error is that the Postgres-JDBC driver is not found. This is correct because only the persistence module knows the dependency (using the correct profile). Second question: if it is not possible to avoid the first question, how can I avoid placing additional dependencies on the module that runs the test?
Expected behavior
I want to run a single unit test (not integration) without database configuration/installation in Quarkus.
Actual behavior
If a single Entity is defined, agroal extension need a configuration to a running database
How to Reproduce?
Add a test like
@QuarkusTest
class CARootCreateControllerImplTest {
@Test
void handleRequest() {
}
}
in a maven module with the agroal extension enabled and no application.properties configured.
Output of uname -a
or ver
Linux 2019-150507 5.10.60.1-microsoft-standard-WSL2
Output of java -version
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.2.3-Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
Apache Maven 3.6.3
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:14 (7 by maintainers)
Thanks a lot @geoand.
My use case is like use case of issue specified by you. I run unit test with annotation @QuarkusTest and the unit test is failed because of hibernate Exception, but my test case is just.
Hibernate is not needed in unit test, but it is required in my extension. So it is my problem https://github.com/quarkusio/quarkus/issues/14927#issuecomment-1087300805
Your proposal https://github.com/quarkusio/quarkus/issues/14927#issuecomment-1061830090 fits to me.
Actually I would like run quarkus test only with specified extension rather than with all extensions that exist in classpath.
@voronovmaksim can you please expand a little on your use case?
It sounds somewhat similar to what I had proposed in https://github.com/quarkusio/quarkus/issues/14927#issuecomment-1061830090