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

FBB*_*FBB 5 java junit unit-testing maven

我想删除单元测试的依赖项。我在这个答案中找到了如何做到这一点。

但我想仅删除一个特定测试的依赖项,而不是所有测试的依赖项。有没有办法做到这一点?

Isa*_*aac 3

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

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

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

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

<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>
Run Code Online (Sandbox Code Playgroud)