How to use pre and post integration goal of failsafe plugin

179 Views Asked by At

I've a scenario where I need to run some pre and post script(java classes) before and after integration test. I'm running integration test using maven-failsafe-plugin and want to use the pre-post functionality of same.

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <includes>
                                <include>**/*IT.java</include>
                            </includes>
                            <testFailureIgnore>true</testFailureIgnore>
                            <parallel>classes</parallel>
                            <threadCount>${parallelCount}</threadCount>
                            <forkCount>${parallelCount}</forkCount>
                            <reuseForks>false</reuseForks>
                            <perCoreThreadCount>false</perCoreThreadCount>
                        </configuration>
                    </plugin>

I'm using https://github.com/temyers/cucumber-jvm-parallel-plugin to run tests in parallel, which generates multiple runner at runtime so cant use Junit's beforeAll/afterAll or beforeEach/afterEach as it will trigger pre/post script for each generated runner.

Can someone help or provide some guidance over the same? Thanks.

1

There are 1 best solutions below

2
ursa On

I guess you need to configure explicitly what exactly you need to run at each specific phase:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M5</version>
    <executions>
        <execution>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
            <configuration>
                <includes>
                    <include>**/*PreHook.java</include>
                </includes>
                <parallel>none</parallel>
            </configuration>
        </execution>
        <execution>
            <goals>
                <goal>integration-test</goal>
            </goals>
        </execution>
        <execution>
            <phase>post-integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
            <configuration>
                <includes>
                    <include>**/*PostHook.java</include>
                </includes>
                <parallel>none</parallel>
            </configuration>
        </execution>
        <execution>
            <goals>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includes>
            <include>**/*IT.java</include>
        </includes>
        <testFailureIgnore>true</testFailureIgnore>
        <parallel>classes</parallel>
        <threadCount>${parallelCount}</threadCount>
        <forkCount>${parallelCount}</forkCount>
        <reuseForks>false</reuseForks>
        <perCoreThreadCount>false</perCoreThreadCount>
    </configuration>
</plugin>