【问题标题】:Using maven properties in citrus testcase在柑橘测试用例中使用 maven 属性
【发布时间】:2018-08-16 07:42:13
【问题描述】:
我想在 citrus 测试用例中使用 maven pom.xml 中定义的属性。
根据环境,激活不同的配置文件,然后定义不同的主机名、端口、...
在 citrus 测试用例中,我想使用这些 maven 属性根据环境将请求定向到正确的主机。
如何解决这个问题?
确实尝试了 env() 和 systemProperty() 函数,但他们没有为我提供值。
另外我确实尝试使用弹簧方法并尝试设置
主机名=@hostname.property.from.maven@
不幸的是,这也不起作用。
使用的版本:
【问题讨论】:
标签:
maven
properties
citrus-framework
【解决方案1】:
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 配置文件激活和环境设置来设置这些属性。