在柑橘测试用例中使用 Maven 属性

Using maven properties in citrus testcase

我想在柑橘类测试用例中使用 Maven pom.xml 中定义的属性。

根据环境不同的配置文件被激活,然后定义不同的主机名、端口、... 在柑橘测试用例中,我想使用这些 Maven 属性根据环境将请求定向到正确的主机。

如何解决这个问题? 确实尝试了 env() 和 systemProperty() 函数,但它们没有为我提供值。 此外,我确实尝试使用 spring 方法并尝试设置 主机名=@hostname.property.from.maven@ 不幸的是,这也不起作用。

使用的版本:

Citrus 测试在 Maven 中使用 maven-failsafe 插件执行(如果需要,也可以使用 maven-surefire)。因此,您需要将系统属性传递给该插件配置以进行测试执行。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
      <systemPropertyVariables>
        <foo.server.host>127.0.0.1</foo.server.host>
        <foo.server.port>8080</foo.server.port>
      </systemPropertyVariables>
    </configuration>
</plugin>

系统属性现在对 Maven 测试执行可见,因此您可以在 Spring 和 Citrus 组件中使用这些属性。例如,您可以使用 Spring 的 属性 占位符配置器。

Maven 故障保护插件配置也能够解析 Maven 项目属性。

<properties>
  <server.host>127.0.0.1</server.host>
  <server.port>8080</server.port>
</properties>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
      <systemPropertyVariables>
        <foo.server.host>${server.host}</foo.server.host>
        <foo.server.port>${server.port}</foo.server.port>
      </systemPropertyVariables>
    </configuration>
</plugin>

您现在应该能够根据 Maven 配置文件激活和环境设置来设置这些属性。