简体   繁体   English

测试套件环境变量

[英]Test Suite Environment Variables

I'm facing a rookie challenge in Qurkus (I'm also new in Java, so sorry if I'm having a silly situation).我在 Qurkus 面临新秀挑战(我也是 Java 的新人,如果我遇到了愚蠢的情况,我深表歉意)。 I'm using ".env" file for local development vars and setting (non-secret) production vars in "application.properties".我正在为本地开发变量使用“.env”文件,并在“application.properties”中设置(非秘密)生产变量。

Things were fine but now that I'm trying to setup a test suite, vars from ".env" are overwriting the ones in "application.properties" (even then ones with "%test" profile) & blocks me to have a development and test environment simultaneously.一切都很好,但现在我正在尝试设置一个测试套件,来自“.env”的变量正在覆盖“application.properties”中的变量(即使是那些具有“%test”配置文件的变量)并阻止我进行开发和测试环境同时进行。

To me this can be done by having a separate (source control indexed) env file for different %profiles like ".env.testing" and somehow assign it to test runner.对我来说,这可以通过为不同的 % 配置文件(如“.env.testing”)创建一个单独的(源代码控制索引)env 文件并以某种方式将其分配给测试运行器来完成。 This pattern is very common in other languages' testing frameworks, but I couldn't find a solution for that.这种模式在其他语言的测试框架中很常见,但我找不到解决方案。

Have any idea?有什么想法吗?

Thanks谢谢

It turned out that Quarkus supports configuration profiles in .env with a different format (but it's not mentioned in the docs).事实证明,Quarkus 支持.env中具有不同格式的配置文件(但文档中未提及)。 So we can simply keep our application.properties file like this:所以我们可以像这样简单地保留我们的application.properties文件:

app.env=production

and the .env file like this:和这样的.env文件:

_DEV_APP_ENV=development
_TEST_APP_ENV=testing

A more detailed doc can be found in this PR .可以在此 PR中找到更详细的文档。

One simple way is to use property expressions in your application.properties file.一种简单的方法是在application.properties文件中使用属性表达式。

For instance, to set the application.host , you can use a property expression like application.host=${HOST:localhost} in your application.properties file.例如,要设置application.host ,您可以在application.properties文件中使用类似application.host=${HOST:localhost}的属性表达式。 If a property named HOST is defined either in your.env file or the application.properties file, then it's value is assigned to application.host, otherwise, the default value (localhost in this example) is assigned instead.如果在 your.env 文件或 application.properties 文件中定义了名为HOST的属性,那么它的值将分配给 application.host,否则,将分配默认值(本例中为 localhost)。

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

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