profiling maven tests


I have a very special case of profiling test cases.

ūnus

Note that following example doesn’t work!

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>target13</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skipTests>false</skipTests>
              <includes>
                <include>com/googlecode/jinahya/test/Target13Test.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile> 
    <profile>
      <id>target14</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skipTests>false</skipTest>
              <includes>
                <include>com/googlecode/jinahya/test/Target14Test.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

Simply failed. I found an issue which is marked as Fixed but this documentation update is what we should read.

duo

There is a work-around for this problem.

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>**/*.java</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>target13</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludes>
                <exclude>NONE</exclude>
              </excludes>
              <includes>
                <include>com/googlecode/jinahya/test/Target13Test.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile> 
    <profile>
      <id>target14</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludes>
                <exclude>NONE</exclude>
              </excludes>
              <includes>
                <include>com/googlecode/jinahya/test/Target14Test.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

It works.

trēs

This is how I solved my problem.

<project>
  <properties>
    <skipTests>true</skipTests>
  </properties>
  <build>
    <plugins>
      <!--
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration/>
      </plugin>
      -->
    </plugins>
  </build>
  <profiles>
    <properties>
      <skipTests>false</skipTests>
    </properties>
    <profile>
      <id>target13</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <includes>
                <include>com/googlecode/jinahya/test/Target13Test.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile> 
    <profile>
      <id>target14</id>
      <properties>
        <skipTests>false</skipTests>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <includes>
                <include>com/googlecode/jinahya/test/Target14Test.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</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