简体   繁体   English

如何使用Maven在测试范围内设置环境变量?

[英]How to setup environment variables in test scope with Maven?

I need to setup some environment variables in my test classes and I don't want to pass them to Maven with -D flag every time. 我需要在测试类中设置一些环境变量,并且我不想每次都使用-D标志将它们传递给Maven。 Is there a way to setup these environment variables in pom.xml file only for tests? 有没有一种方法可以仅在测试中在pom.xml文件中设置这些环境变量?

I've tried to setup them with System.getenv().put() but without success ( java.lang.UnsupportedOperationException ) 我试图用System.getenv().put()设置它们,但是没有成功( java.lang.UnsupportedOperationException

Most maven plugins seem to support the configuration element. 大多数Maven插件似乎都支持配置元素。 This should explain what you need Configuring surefire plugin 这应该说明您需要什么配置surefire插件

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

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