我有一些缓慢的测试依赖于我不想在每次使用 Maven 构建项目时都运行的数据库。我已按照http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#excludedGroups的说明将 excludeGroups 元素添加到我的 pom 文件中,但我似乎无法让它工作。
我创建了一个最小的项目。这是 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>exclude</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<excludedGroups>db</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.14</version>
</dependency>
</dependencies>
</project>
这些是两个测试类:
public class NormalTest {
@Test
public void fastTest() {
Assert.assertTrue(true);
}
}
和
public class DatabaseTest {
@Test(groups={"db"})
public void slowTest() {
Assert.assertTrue(false);
}
}
然而,这两个测试仍然运行。我无法弄清楚我做错了什么。