簡體   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