Last Updated: February 25, 2016
·
252
· alvarogarcia7

Make maven execute other tests

By default, maven's surefire plugin will only execute a set of tests (matching a regex).

In my team, we name our test files ending in "Should", eg:

* LinkedListShould, with methods
   * not_have_any_object_by_default
   * have_one_element_after_being_empty_then_adding_it
   * etc
*  BinarySearchTreeShould, with methods
   * search_in_logN_time

etc

Theses tests are not executed by default by surefire, so we add this building configuration to pom.xml:

<plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
      <includes>
        <include>**/**Test.java</include>
        <include>**/**Should.java</include>
      </includes>
    </configuration>
</plugin>

Then, you execute by default the tests ending in Should and ending in Test

Source: http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html