How to execute a method once before running maven surefire

I have a test suite for which some setup code must be installed before starting to make sure that some of the data is correct in our database.

We use the maven surefire plugin to run tests in parallel. ${tests.wildcard}set by profile.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.16</version>
    <configuration>
        <forkCount>4</forkCount>
        <reuseForks>false</reuseForks>
        <includes>
            <include>${tests.wildcard}</include>
        </includes>
    </configuration>
</plugin>

I would like to be able to run the method only once for all maven execution before surefire runs my tests in parallel. How can i do this?

+4
source share
1 answer

You may have a special test case that executes your verification code (and crash in case).

Maven Surefire ( ) Maven test (, process-test-classes): , Maven .

test , init.

:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <excludes>
            <exclude>**/InitTest.java</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>test-init</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <test>InitTest</test>
            </configuration>
        </execution>
    </executions>
</plugin>

, Surefire init. ( test) init ( <test>, priority include/exclude).

, :

  • init (, , )


, , , , ( default-test ), ( ), ( , ).
test, , pom.

+3

Source: https://habr.com/ru/post/1625222/


All Articles