I have a basic question about Quarkus testing, I would like to execute the command ./mvnw clean test
but I need to use a token to init the application.
I have configured application-test.properties
file to store the token:
discord.token=XYZ
So, in my code I was expecting to be able to retrieve the value of the discord.token
property:
@ConfigProperty(name = "discord.token")
private String token;
Is it possible? if not, how can I do this?
thanks
The dev
profile is used by dev mode ( ./mvnw quarkus:dev
). If you want to define a property for your tests, you need to use the test
profile.
You can do that either with a suffixed file as you did (but with the -test
suffix ie application-test.properties
) or use %test.
in front of your properties ( %test.discord.token=XYZ
) in the regular application.properties
.
See https://quarkus.io/guides/config-reference#profiles for more information.
You can instead put your application.properties
file in src/test/resources
instead of application-test.properties
in src/main/resources
You can also use mvn -Dquarkus.config.locations=/tmp/foo.properties test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.