如何将参数传递给Maven测试 [英] How to pass parameter to maven test
问题描述
我有一个在两个环境中运行的测试套件.
有时候,我想在localhost:8080上运行测试,有时想在localhost:8585上运行测试.
Jenkins通过"mvn test
"命令运行测试.
如何通过参数传递端口?类似于"MVN测试8080".
我在maven pom.xml上添加了一个插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>fileName</name>
<value>${fileName}</value>
</property>
</systemProperties>
</configuration>
</plugin>
并使用junit代码获取参数
String fileName = System.getProperty("fileName");
之后,我使用-DfileName参数运行测试
mvn clean test -DfileName="config-test.xml"
现在,我可以将所有配置放入xml文件中,并使用正确的参数加载适当的文件.
mvn clean test -DfileName="config-test.xml"
或
mvn clean test -DfileName="config-homolog.xml"
我用Sandra Sukarieh和mvn test" command.
How could I pass the port by parameter? Something like "mvn test 8080".
I add a plugin on maven pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>fileName</name>
<value>${fileName}</value>
</property>
</systemProperties>
</configuration>
</plugin>
And get the parameter in junit code with
String fileName = System.getProperty("fileName");
After, I run my tests with -DfileName argument
mvn clean test -DfileName="config-test.xml"
Now, I can put all configurations in xml file and load appropriate file with the corrects parameters.
mvn clean test -DfileName="config-test.xml"
or
mvn clean test -DfileName="config-homolog.xml"
I solved the problem with the tips from Sandra Sukarieh and http://syntx.io/how-to-pass-parameters-to-the-junit-tests-from-the-maven-surefire-plugin/
Thank you very much
这篇关于如何将参数传递给Maven测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!