java - 排除一个特定单元测试的 Maven 依赖项

标签 java unit-testing maven junit

我想删除单元测试的依赖项。我找到了怎么做 in this answer .

但我只想删除一个特定测试的依赖项,而不是我所有测试的依赖项。有办法吗?

最佳答案

不是通过使用一次 Surefire 执行。

您将必须定义 Surefire 插件的两个执行:一个包含大多数测试的完整类路径,另一个包含需要它的单个测试的专用类路径。

遵循 Surefire 插件的文档:http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

您必须创建两个执行,并将它们都绑定(bind)到 test 阶段。使用以下示例作为框架(您必须调整 includeexclude 模式,以及排除的类路径 Artifact ):

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <executions>
            <execution>
                <id>full-cp</id>
                <phase>test</phase>
                <goals>
                    <goal>test</goal>
                </goals>
                <configuration>
                    <includes>
                        <include>**/Test*.java</include>
                    </includes>
                    <excludes>
                        <exclude>MyFancyTest.java</exclude>
                    </excludes>
                </configuration>
            </execution>
            <execution>
                <id>special-cp</id>
                <phase>test</phase>
                <goals>
                    <goal>test</goal>
                </goals>
                <configuration>
                    <includes>
                        <include>MyFancyTest.java</include>
                    </includes>
                    <classpathDependencyExcludes>
                        <classpathDependencyExcludes>excluded-artifact</classpathDependencyExcludes>
                    </classpathDependencyExcludes>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

关于java - 排除一个特定单元测试的 Maven 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16019550/

相关文章:

java - 用java显示网站

c# - 如何将基于约定的自定义与 AutoFixture 的 [AutoData] 属性相结合?

maven - 仅当发布时才进行Gradle发布

java - Maven 编译给出 : Cannot find symbol - For a class sitting in the same app

java - 更改方法findByOneCss,他收到了不止一种含义和所有

java - 每个 android 的 ConcurrentModificationException

Java 在分层生成器模式中避免类转换警告

c# - 一次性方法的单元测试

c# - 使用 rhino mock 的 lambda 单元测试失败

eclipse - Eclipse中如何在tomcat中部署maven项目