我们可以在maven-surefire-plugin之前执行exec-maven-plugin吗?

时间:2016-12-21 09:13:41

标签: maven maven-surefire-plugin exec-maven-plugin

是否可以在maven-surefire-plugin之前运行exec-maven-plugin,我在运行期间观察到的是maven-surefire-plugin首先执行,即使标签中的序列是第二个。我的方案是执行JAVA CLASS(使用exec-maven-plugin)生成我的testng.xml并可以使用(maven-surefire-plugin)运行它。

2 个答案:

答案 0 :(得分:3)

首先,如果执行test绑定到maven-surefire-plugin阶段,则执行jar之后执行此操作是正常的。原因是您可能正在处理将testwhich has a default binding of the Surefire Plugin打包到default-test阶段的项目。无论插件在POM中的声明位置如何,此默认执行始终是第一个调用的执行。在日志中,您将发现此执行的ID为testng.xml

有一种方法可以在运行测试之前通过利用the phases invoked before the phase test来执行操作。在您的情况下,您的目标是生成测试资源generate-test-resources,因此使用<phase>generate-test-resources</phase> 阶段是合适的,其目的是创建测试所需的资源。因此,您只需指定

即可
exec-maven-plugin

执行生成testng.xml的{​​{1}}。

然后,您可以将生成的testng.xmlsuiteXmlFiles元素一起使用,请参阅Using Suite XML Files

答案 1 :(得分:0)

我是这样实现的:

  1. 我添加了测试脚本/java 主类,我想在 Cucumber Test Suite 之前执行,在以下文件夹中: enter image description here

  2. 在 POM.xml 中添加以下内容...

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>

            <execution>
                <phase>process-resources</phase>
                <goals>
                    <goal>add-source</goal>
                </goals>
                <configuration>
                    <sources>

                        <source>src/test/java/BeforeSuite</source> <!-- source folder where Before Suite scripts are saved -->
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>

            <execution>
                <id>before-test-suite-scripts</id>
                <phase>generate-test-resources</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>BeforeSuite.HelloBeforeSuiteScript</mainClass> <!-- <packagename>.<className> -->
                </configuration>
            </execution>
        </executions>
    </plugin>

当运行 mvn clean verify 时,测试套件脚本将在测试套件执行之前运行。 enter image description here

相关问题