views:

1508

answers:

2

I would like my Maven builds to run most unit tests. But there are unit tests in one project which are slower and I'd like to generally exclude them; and occasionally turn them on.

How do I do this?

I know about -Dmaven.test.skip=true, but that turns off all unit tests.

I also know about skipping integration tests, described here. But I do not have integration tests, just unit tests, and I don't have any explicit calls to the maven-surefire-plugin. (I am using Maven 2 with the Eclipse-Maven plugin).

+4  A: 

What about skipping tests only in this module ?

In the pom.xml of this module:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4.2</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Eventually, you can create a profile that will disable the tests (still the pom.xml of the module) :

<project>
  [...]
  <profiles>
    <profile>
      <id>noTest</id>
      <activation>
        <property>
          <name>noTest</name>
          <value>true</value>
        </property>
      <activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  [...]
</project>

With the latter solution, if you run mvn clean package, it will run all tests. If you run mvn clean package -DnoTest=true, it will not run the tests for this module.

romaintaz
Thanks that worked. The first code snippet skips the test; I may later use your further suggestion to define another profile.My confusion was in the fact that my pom was invoking surefire implicitly. There was no mention of the surefire plugin in my pom.xml. Nonetheless, the code to configure the surefire plugin correctly did so.
Joshua Fox
+1  A: 

I think this is easier, and also has the benefit of working for non-surefire tests (in my case, FlexUnitTests)

<profile>
   <id>noTest</id>
    <properties>
   <maven.test.skip>true</maven.test.skip>
    </properties>
 </profile>
Luiz Henrique Martins Lins Rol