Florian
Florian

Reputation: 89

Prevent maven from skipping tests (default = skip)

My pom.xml looks like this:

<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>

So by default, the maven builder is supposed to skip all tests. Is it possible to activate the tests like mvn -Dmaven.test.skip=false test? What I am trying to do, is to only execute the test suite when the code is built with jenkins.

Upvotes: 0

Views: 1605

Answers (1)

khmarbaise
khmarbaise

Reputation: 97547

The default of the maven-surefire-plugin is not to skip the tests. So the best is to remove the

<skipTests>true</skipTests> 

entry from your pom. Furthermore having Test suites in relationship with Maven does not make sense.

But you can of course handle that via a profile which is activated by Jenkins environment like this:

<profiles>
  <profile>
     <id>default-build</id>
     <activation>
      <activeByDefault>true</activeByDefault>
     </activation>
     <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <skipTests>true</skipTests>
          </configuration>
        </plugin>
      </plugins>
     </build>
   </profile>

   <profile>
    <id>jenkins-build</id>
    <activation>
      <property>
        <name>JENKINS_URL</name>
      </property>
      <build>
        <plugins>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
         </plugin>
       </plugins>
      </build>
    </activation>
  </profile>
</profiles>

Btw. Use a more up-to-date maven-furefire-plugin version currently 2.14.1.

Upvotes: 2

Related Questions