Home > Blockchain >  Execute only some subset of integration tests with maven-failsafe-plugin
Execute only some subset of integration tests with maven-failsafe-plugin

Time:01-31

We have a set of integration tests, which all end with IT. Out of those, there is some specific subset, which we would like to execute separately. Let's say their names end with SpecialIT. So what we want to achieve is two configurations of the failsafe plugin:

  • To execute all tests, ending with IT, but not with SpecialIT -> this is easy. Just normal inclusion and exclusion by those names.
  • To execute all tests, ending with SpecialIT, but not all others ...IT.

I thought it would be natural to create some dedicated profile and use a separate failsafe configuration with a negative lookbehind regex for that, so ended up with this configuration (had to use &lt; instead of <, as that one is not allowed there):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>%regex[.*(?&lt;!Special)IT.*]</exclude>
        </excludes>
        <includes>
            <include>**/*SpecialIT.*</include>
        </includes>
    </configuration>
</plugin>

But when I try to run this - I'm getting the following error:

Exclamation mark not expected in 'exclusion': %regex[.*(?<!Special)IT.*]

Reading the documentation of the failsafe plugin - I see this:

The syntax in parameter excludes and excludesFile should not use (!).

So the question is: is there any other way to achieve this, without, let's say, renaming all our integration tests into ...StandardIT and ...SpecialIT?

I was thinking in the direction of tags, test suit names or smth., but in our project we currently have a mix of JUnit5, JUnit4 and Spock (Groovy) tests, so it becomes not so straightforward.

P.S. If I just use this configuration - all IT tests are getting disabled and nothing is executed:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/*IT.*</exclude>
        </excludes>
        <includes>
            <include>**/*SpecialIT.*</include>
        </includes>
    </configuration>
</plugin>

CodePudding user response:

Thanks to @andrey-b-panfilov, I realized that my problem was that I somehow was under an impression (based on this) that all ...IT tests are always executed by default... But this is, of course, only until the <includes> is overwritten. So, the solution is eventually to just define the following two configurations:

  • To execute all but SpecialIT:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <includes>
            <include>**/*IT.*</include>
        </includes>
        <excludes>
            <exclude>**/*SpecialIT.*</exclude>
        </excludes>
    </configuration>
</plugin>
  • To execute only SpecialIT:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <includes>
            <include>**/*SpecialIT.*</include>
        </includes>
    </configuration>
</plugin>
  • Related