运行 来自 Git Bash 的 Maven 目标失败

Run Maven goal from Git Bash fail

我配置了 pom.xml 以执行 TestNG 套件 文件。

执行的文件作为参数传递给 Maven。

但麻烦的是,当我从控制台 运行:

mvn integration-test -Dmain-suite=${circuit-suite}

运行正常,开始测试

但是当我尝试从 Git Bash 运行 它时,我得到了 Error:

[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/command 行变量 circuit-suite 扩展为 d:\HOME\IdeaProjects\webclient_suite\suite。尝试

mvn integration-test -Dmain-suite=${circuit-suite}

注意 $ 前的反斜杠。这告诉 BASH 不理会这个变量,只将它传递给 Maven。