java—如何让带有@tag注解的junit测试在带有@includetags的套件中执行?

vhmi4jdf  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(397)

我有以下代码:
测试等级:

@Tag("foo")
class SomeIT
{

   @Test
   public void testSomeStuff()
   {
       ...
   }

}

套房等级:

@RunWith(JUnitPlatform.class)
@IncludeTags({"foo"})
//@SelectPackages("org.foo")
public class SomeITSuite
{
}

我的 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">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.foo</groupId>
    <artifactId>bar</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <version.slf4j>1.7.30</version.slf4j>
        <version.junit>5.7.0</version.junit>
        <version.junit.platform.runner>1.7.0</version.junit.platform.runner>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- for testing -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${version.junit}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>${version.junit.platform.runner}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>integration-tests</id>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <configuration>
                            <includes>
                                <include>**/*ITSuite.java</include>
                            </includes>
                        </configuration>
                        <executions>
                            <execution>
                                <id>integration-test</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>verify</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

这将在idea和控制台中执行0个测试的套件(使用 mvn clean install -Pintegration-tests ).
如果我恢复了 @SelectPackages("org.foo") ,它将运行所有的测试,不管它们是否被标记。我错过了什么?这是虫子吗?

mwg9r5ms

mwg9r5ms1#

显然,当junit扫描这些类时,它并没有识别出以 IT 作为集成测试。我不得不把它们改名为 *ITTest 事情开始起作用了。
如果有人对更多细节感兴趣,你可以看看这个pull请求。

相关问题