繁体   English   中英

Quarkus 单元测试和属性

[英]Quarkus unit-testing and properties

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

我已经配置了application-test.properties文件来存储令牌:

discord.token=XYZ

因此,在我的代码中,我期望能够检索discord.token属性的值:

@ConfigProperty(name = "discord.token")
private String token;

可能吗? 如果没有,我该怎么做?

谢谢

dev配置文件由开发模式( ./mvnw quarkus:dev )使用。 如果要为测试定义属性,则需要使用test配置文件。

您可以像以前那样使用带后缀的文件(但使用-test后缀,即application-test.properties )或使用%test. 在常规application.properties中的属性( %test.discord.token=XYZ )前面。

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

您可以改为将application.properties文件放在src/test/resources中,而不是将application-test.properties放在src/main/resources

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

暂无
暂无

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

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