简体   繁体   English

Quarkus 单元测试和属性

[英]Quarkus unit-testing and properties

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.我有一个关于 Quarkus 测试的基本问题,我想执行命令./mvnw clean test但我需要使用令牌来初始化应用程序。

I have configured application-test.properties file to store the token:我已经配置了application-test.properties文件来存储令牌:

discord.token=XYZ

So, in my code I was expecting to be able to retrieve the value of the discord.token property:因此,在我的代码中,我期望能够检索discord.token属性的值:

@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 ). dev配置文件由开发模式( ./mvnw quarkus:dev )使用。 If you want to define a property for your tests, you need to use the test profile.如果要为测试定义属性,则需要使用test配置文件。

You can do that either with a suffixed file as you did (but with the -test suffix ie application-test.properties ) or use %test.您可以像以前那样使用带后缀的文件(但使用-test后缀,即application-test.properties )或使用%test. in front of your properties ( %test.discord.token=XYZ ) in the regular application.properties .在常规application.properties中的属性( %test.discord.token=XYZ )前面。

See https://quarkus.io/guides/config-reference#profiles for more information.有关详细信息,请参阅https://quarkus.io/guides/config-reference#profiles

You can instead put your application.properties file in src/test/resources instead of application-test.properties in src/main/resources您可以改为将application.properties文件放在src/test/resources中,而不是将application-test.properties放在src/main/resources

You can also use mvn -Dquarkus.config.locations=/tmp/foo.properties test您也可以使用mvn -Dquarkus.config.locations=/tmp/foo.properties test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM