问题
I plan to use PostgreSQL as the database for my Quarkus application but I would like the convenience of using H2 in my tests.
Is there a way I can accomplish such a feat?
回答1:
Quarkus provides the H2DatabaseTestResource which starts an in memory H2 database as part of the test process.
You will need to add io.quarkus:quarkus-test-h2
as a test
scoped dependency and annotate your test with @QuarkusTestResource(H2DatabaseTestResource.class)
.
You will also need to have something like:
quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:test
quarkus.datasource.driver=org.h2.Driver
in src/test/resources/application.properties
In order for the application use PostgreSQL as part of its regular run, quarkus-jdbc-postgresql
should be a dependency and
quarkus.datasource.url=jdbc:postgresql://mypostgres:5432
quarkus.datasource.driver=org.postgresql.Driver
should be set in src/main/resources/application.properties
来源:https://stackoverflow.com/questions/55063778/how-can-use-an-in-memory-h2-database-when-testing-my-quarkus-application