【问题标题】:Run Maven goal from Git Bash fail从 Git Bash 运行 Maven 目标失败
【发布时间】:2015-06-19 19:14:09
【问题描述】:

我为执行 TestNG 套件 文件配置了我的 pom.xml

执行的文件作为参数传递给 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 sn-p:

<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} 的值是多少?
  • @WalterA 它是 pom 属性 - ${basedir}/src/test/resources/webClientIMPSuites/CircuitUITests.xml
  • 我以为你用命令行 mvn integration-test -Dmain-suite=${circuit-suite} 否决了它。
  • @WalterA 我明确地说我通过 main-suite 传递的属性。此套件文件保存为 pom 属性。

标签: java git bash maven testng


【解决方案1】:

您可能有一个 shell/命令行变量 circuit-suite,它扩展为 d:\HOME\IdeaProjects\webclient_suite\suite。试试

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2018-05-06
    相关资源
    最近更新 更多