views:

1233

answers:

2

I would like to skip only a single test while launching mvn install.

Is there a way to do that ?

+4  A: 

With junit 4, I add an @Ignore annotation when I want to do that. This would work for you, unless you want to only sometimes ignore the test, or only ignore it when the build runs from maven. If this is the case, then I would ask "Why?"

Tests should be consistent, they should be portable, and they should always pass. If a specific test is problematic I would consider re-writing it, removing it entirely, or moving it to a different test suite or project.

Steve Reed
The use case is that someone in my team is currently fixing a test and I want to launch all others tests but not this one until it's working again. So you're right, I should disabled it by code temporary.
paulgreg
+2  A: 

i think this should work if using this command:

mvn archetype:create -DgroupId=test -DartifactId=test

(for test change pom.xml and test-class to the following and use mvn install)

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>test</name>
<url>http://maven.apache.org&lt;/url&gt;
<build>
 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <source>1.5</source>
    <target>1.5</target>
   </configuration>
  </plugin>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
    <excludes>
     <exclude>
      test/AppTest.java
              </exclude>
    </excludes>
   </configuration>
  </plugin>
 </plugins>
</build>
<dependencies>
 <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.5</version>
  <scope>test</scope>
 </dependency>
</dependencies>

test-class:

package test;
import org.junit.Test;
import static org.junit.Assert.fail;
public class AppTest 
{
    @Test
    public void test_it() {
        fail("not implemented");
    }
}
rschmid