Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override config property for one Unittest in Quarkus

In my Quarkus-Application an Observer of StartupEvent inserts default data into my database if a specific config-property is true. For one particular UnitTest I want my database to be empty.

I would think that there is some way to override configuration values for one unittest. Is that true, or is there a better way?

like image 314
Obyoxar Avatar asked Nov 15 '19 20:11

Obyoxar


People also ask

How do I set the values for the Quarkus configuration properties?

Add configuration properties to your configuration file where <KEY> is the property name and <VALUE> is the value of the property: The following example shows how to set the values for the greeting.message and the greeting.name properties in the Quarkus config-quickstart project: Use quarkus as a prefix to Quarkus properties.

How to inject an individual property configuration into a Quarkus project?

You can use the @ConfigProperty annotation to map an object property to a key in the MicroProfile ConfigSources file of your application. This procedure shows you how to inject an individual property configuration into a Quarkus config-quickstart project. You have created the Quarkus config-quickstart project.

Should I use the Quarkus prefix for application specific properties?

Therefore, the quarkus. prefix should never be used for application specific properties. Some Quarkus configurations only take effect during build time, meaning is not possible to change them at runtime. These configurations are still available at runtime but as read-only and have no effect in Quarkus behaviour.

Where is the Quarkus application configuration file?

Quarkus Application configuration file The Quarkus Application configuration file is loaded from the classpath resources, for instance src/main/resources/application.properties, src/test/resources/application.properties or from a jar dependency that contains an application.properties entry.


2 Answers

I would suggest using test profiles

https://quarkus.io/blog/quarkus-test-profiles/

like image 57
gaetanc Avatar answered Oct 15 '22 04:10

gaetanc


Have you tried out by using a test profile for that property in your application.properties ?

Something like this:

—default value is A

myProp=A

—this is the test profile, which overrides the default value

%tst.myProp=B

like image 32
Serkan Avatar answered Oct 15 '22 05:10

Serkan