Maven Surefire plugin patterns

Today I hit a case where some of my tests wouldn’t be picked up to run during Maven’s testing phase. The reason for that is the way the Surefire plugin is picking up names to include by default, namely the **/*Test.java, **/Test*.java, **/*TestCase.java name patterns.

If we want to include all the tests adhering to a common naming convention we can use regex to explicitly specify inclusion in the Surefire plugin:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.11</version>
        <configuration>
          <includes>
            <include>%regex[.*MyNamingConvention*]</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s