我有一个 Maven TestNG 项目,并且正在尝试将几个命令行参数传递到 testng.xml 文件中。
testng.xml 文件如下所示:
<suite name="Test Suite" parallel="classes" thread-count="100" >
<test name="VIP Tests">
<parameter name="browser" value="${browser}" />
<groups>
<run>
<include name="${test.scope}" />
</run>
</groups>
<packages>
<package name="com.tests.*" />
</packages>
</test>
</suite>
pom.xml 文件如下所示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test_Project</groupId>
<artifactId>TP_X</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
</resource>
</resources>
<sourceDirectory>${src.dir}</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
现在,每次我尝试执行 Maven 测试命令时
mvn clean test -U -Dtest.scope=smoke -Dbrowser=chrome
我在命令行中收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project VIP_QE: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process
[ERROR] java.util.regex.PatternSyntaxException:
[ERROR] Illegal repetition near index 0
[ERROR] ${test.scope}
有人可以帮忙吗?我已经被这个问题困扰了大约一周。
TestNG 和 Surefire 不支持${var}
符号。
但你可以使用Maven的过滤功能。然后你必须选择修改后的资源:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test_Project</groupId>
<artifactId>TP_X</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<sourceDirectory>${src.dir}</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>target/test-classes/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
注意之间的区别testResources
and resources
: 如何在maven中过滤测试资源?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)