简体   繁体   English

Maven / Netbeans具有不同的测试配置文件和环境变量

[英]Maven/Netbeans Have different testing profiles and environment variables

We are trying to do Selenium tests for our java web application. 我们正在尝试对我们的Java Web应用程序进行Selenium测试。 We would like to be able to quickly configure our tests with a combination of the java function "System.getProperty" and modifying the profiles available for the test. 我们希望能够结合使用Java函数“ System.getProperty”和修改可用于测试的配置文件来快速配置测试。

The reason for doing this is so that we can test different servers with a simple change of the dropdown box in netbeans (from < default config > to "server name/details"). 这样做的原因是,我们可以通过更改netbeans中的下拉框(从<default config>到“ server name / details”)来测试不同的服务器。 Our servers run things like a Snapshot, RC, and hotfix branch so this would be very helpful in tracking down when bugs are introduced. 我们的服务器运行Snapshot,RC和hotfix分支之类的东西,因此这对于跟踪引入错误的时间非常有帮助。

Our current method for doing this is modifying the test variables before each run to target the server we want (yuck!). 我们当前执行此操作的方法是在每次运行之前修改测试变量以定位到我们想要的服务器(糟糕!)。

Any thoughts would be helpful 任何想法都会有所帮助

The simplest mechanism might well be to create profiles in your POM that are activated by a system property or environment variable. 最简单的机制很可能是在POM中创建由系统属性或环境变量激活的配置文件

An example from the Maven documentation (with small modifications for clarity): Maven文档中的示例(为清晰起见,做了一些小的修改):

<profiles>
  <profile>
    <activation>
      <property>
        <name>myProperty</name>
        <value>test</value>
      </property>
    </activation>
    ...
  </profile>
</profiles>

Which you'd activate manually with: 您可以通过以下方式手动激活:

mvn groupId:artifactId:goal -DmyProperty=test

You'd enable this based on an environment variable by using the fact that Maven maps environment vars into properties with the name env.… (with case normalization on Windows): 您将通过使用Maven将环境var映射到名称为env.…属性(在Windows上进行大小写规范化)这一事实来基于环境变量启用此功能:

<profiles>
  <profile>
    <activation>
      <property>
        <name>env.ENVIRONMENT</name>
        <value>test</value>
      </property>
    </activation>
    ...
  </profile>
</profiles>

Which you'd activate with: 您可以通过以下方式激活:

export ENVIRONMENT=test  # Does not need to be done every build, just per session
mvn groupId:artifactId:goal

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

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