2

I'm working on a Maven based Java open source project hosted on Github. We use Travis for continuous integration.

Some of the more complex JUnit tests don't currently pass in the Travis environment though they do pass locally.

Question: Is there a quick and easy way to mark particular test classes or methods as "Do not run on Travis" so we can move forward while I figure out how to fix the Travis environment for these tests?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • 1
    I would ask why those test don't run on travis? So you have things done in a tests which you shouldn't do, cause you say locally they run but on travis they don't....I would take a deep look into those tests why they don't run on travis.. – khmarbaise Apr 27 '16 at 13:37

1 Answers1

2

A possible solution would be to add a maven profile to the concerned project and configure the maven-surefire-plugin to exclude these tests from its test goal execution.

An example would be:

<profiles>
    <profile>
        <id>trasis</id>
        <build>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                  <excludes>
                    <!-- exclude tests here -->
                    <exclude>**/TestCircle.java</exclude>
                    <exclude>**/TestSquare.java</exclude>
                  </excludes>
                </configuration>
              </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Then your trasis build should run

mvn clean install -Ptrasis

Which will:

  • activate the profile above
  • apply the customized configuration for the Surefire Plugin
  • exclude configured tests (patterns) from the test phase

This profile can then be ignored by local builds while still active on Trasis. Once the issue is fixed, it can then be removed completely from the trasis configuration and from the pom file itself.


Alternatively, and especially if you cannot change the concerned pom file, you can exclude tests (and methods) using the test option and a well crafted regex:

Since 2.19 a complex syntax is supported in one parameter (JUnit 4, JUnit 4.7+, TestNG):
"-Dtest=???Test, !Unstable*, pkg/**/Ci*leTest.java, *Test#test*One+testTwo?????, #fast*+slowTest"
"-Dtest=Basic*, !%regex[.*.Unstable.*], !%regex[.*.MyTest.class#one.*|two.*], %regex[#fast.*|slow.*]"

mvn clean install -Dtest=*Test,!FromThisClass#excludeThisMethod
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128