从Maven中排除TestNG组

从Maven中排除TestNG组

本文介绍了从Maven中排除TestNG组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些缓慢的测试,这些测试依赖于我每次使用Maven构建项目时都不想运行的数据库.我已经按照 http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#excludedGroups ,但我似乎无法使其正常工作.

I have some slow tests that rely on the database that I don't want run every time I build my project with Maven. I've added the excludedGroups element to my pom file as explained http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#excludedGroups but I can't seem to get it working.

我创建了一个最小的项目.这是pom.xml:

I've created a minimal project. Here is the 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);
    }
}

但是,这两个测试仍在运行.我不知道自己在做什么错.

However both tests still run. I can't figure out what I'm doing wrong.

推荐答案

我最终创建了外部测试服:

I ended up creating external test suits:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="tests">
        <test name="standard">
        <groups>
            <run>
                <exclude name="slow" />
                <exclude name="external" />
                <exclude name="db" />
            </run>
        </groups>
        <packages>
            <package name="com.test.*" />
        </packages>
    </test>
</suite>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="tests">
    <test name="full">
        <packages>
            <package name="com.test.*" />
        </packages>
    </test>
</suite>

,并指定要在配置文件中运行的内容:

and specifyied which to run in a profile:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.11</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>src/test/resources/suites/standard.xml</suiteXmlFile>
        </suiteXmlFiles>
     </configuration>
</plugin>

...

<profile>
    <id>fulltest</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/suites/full.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

这篇关于从Maven中排除TestNG组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 17:39