Eclipse 中的 TestNG,对未定义变量 env.DOMAIN_PATH 的引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39642358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TestNG in Eclipse, Reference to undefined variable env.DOMAIN_PATH
提问by sujoe
I just got a error when I try to run a unit test in Eclipse with TestNG, the error message is: Reference to undefined variable env.DOMAIN_PATH
当我尝试使用 TestNG 在 Eclipse 中运行单元测试时出现错误,错误消息是:Reference to undefined variable env.DOMAIN_PATH
but this problem does not exist when I run it in Intellj or with maven.
但是当我在 Intellj 或 maven 中运行它时,这个问题不存在。
any one experience this problem?
有人遇到过这个问题吗?
I use Eclipse Mars.2 Release (4.5.2), and updated TestNG plugin version 6.9.12.201607091356
我使用 Eclipse Mars.2 Release (4.5.2),并更新了 TestNG 插件版本 6.9.12.201607091356
thanks.
谢谢。
回答by justnisar
When I was trying to run TestNG, I got the same error. I changed the preferences in Eclipse for TestNG -> Maven so that systemPropertyVariables and environmentVariables are unchecked, and I was able to run the test cases successfully.
当我尝试运行 TestNG 时,我遇到了同样的错误。我在 Eclipse 中更改了 TestNG -> Maven 的首选项,以便取消选中 systemPropertyVariables 和 environmentVariables,并且我能够成功运行测试用例。
Before
前
After
后
回答by XuQing Tan
you need to enable the 'environmentVariables' option at either Eclipse workspace level preferences or project level properties, for example for workspace level: navigate to Eclipse preference -> TestNG -> Maven -> enable option 'environmentVariables'. By default it's disabled. see more details in the official guide
您需要在 Eclipse 工作区级别首选项或项目级别属性中启用“environmentVariables”选项,例如对于工作区级别:导航到 Eclipse 首选项 -> TestNG -> Maven -> 启用选项“environmentVariables”。默认情况下它是禁用的。在官方指南中查看更多详细信息
回答by Appu Mistri
In case you are working with maven project, setting your custom property to some default value could resolve this issue. below is a sample.
如果您正在使用 Maven 项目,将自定义属性设置为某个默认值可以解决此问题。下面是一个示例。
<properties>
<environment>local</environment>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<environment>${environment}</environment>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
you can make use of "environment" property in project using below call.
您可以使用以下调用在项目中使用“环境”属性。
System.getProperty("environment");