我配置了 pom.xml
来执行 TestNG suite 文件。
执行的文件作为参数传递给 Maven。
但问题是,当我从控制台运行时:
mvn integration-test -Dmain-suite=${circuit-suite}
一切正常,测试执行已开始。
但是当我尝试从 Git Bash
运行它时,我收到错误:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.892 s
[INFO] Finished at: 2015-04-14T11:30:20+02:00
[INFO] Final Memory: 31M/363M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test (default-test) on project webClientI
MPAutomation: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test failed: There was an e
rror in the forked process
[ERROR] org.apache.maven.surefire.testset.TestSetFailedException: Suite file d:\HOME\IdeaProjects\webclient_suite\suite is not a valid file
[ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:116)
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:83)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[ERROR] -> [Help 1]
我无法调查为什么它搜索 suite
作为套件文件。
这是 pom 片段:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<smoke-suite>${basedir}/src/test/resources/webClientIMPSuites/SmokeSuiteCI.xml</smoke-suite>
<circuit-suite>${basedir}/src/test/resources/webClientIMPSuites/CircuitUITests.xml</circuit-suite>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<executions>
<execution>
<id>default-test</id>
<phase>integration-test</phase>
<configuration>
<suiteXmlFiles>
<suiteXmlFiles>${main-suite}</suiteXmlFiles>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我将 testng 套件文件作为参数传递给 Maven。可执行suite
文件保存为pom 的属性。在这种情况下它的值为:
${basedir}/src/test/resources/webClientIMPSuites/CircuitUITests.xml
为什么会发生这种奇怪的行为?
怎么解决呢。并在 Git Bash
上执行。
最佳答案
您可能有一个 shell/命令行变量 Circuit-suite
,它扩展为 d:\HOME\IdeaProjects\webclient_suite\suite
。尝试一下
mvn integration-test -Dmain-suite=\${circuit-suite}
注意$
之前的反斜杠。这告诉 BASH 保留这个变量并将其传递给 Maven。
关于java - 从 Git Bash 运行 Maven 目标失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29622910/