JUnit 5 vintage not 运行 tests in nested static 类

JUnit 5 vintage not running tests in nested static classes

我有 JUnit 4 测试,我正在尝试 运行 使用 JUnit 5 Vintage。

我在嵌套静态中有很多测试类。顶级 类 运行 中的测试很好,但嵌套 类 中的测试不 运行.

例如:

public class SomeOuterClass {
    @Test
    public void outerTest() {
        // test runs
    }

    public static class SomeInnerTests {
        @Test
        public void someTest() {
            // test doesn't run
        }
    }

    public static class OtherInnerTests {
        @Test
        public void otherTest() {
            // test doesn't run
        }
    }
}

我尝试将 junitPlatform.filters.includeClassNamePatterns 设置为 '^.*Tests?$', '^.*Tests?$.*$',但没有成功。

您可以使用 JUnit 5 Vintage

通过 JUnit 5 执行 JUnit 4

通过导入 JUnit Vintage Engine 使用它:

<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>${junit5.vintage.version}</version>
    <scope>test</scope>
</dependency>

JUnit 5 Vintage 在最终版本中添加了对 运行 嵌套静态 类 的支持。

默认情况下,它只查找名称以 "Test(s)" 结尾的 类。要包含未这样命名的嵌套静态 类,请在构建文件中设置以下内容。

junitPlatform.filters.includeClassNamePatterns '^.*Tests?$', '^.*Tests?\$.*$'