【问题标题】:JUnit 5 vintage not running tests in nested static classesJUnit 5 老式未在嵌套静态类中运行测试
【发布时间】:2017-08-23 16:47:29
【问题描述】:

我尝试使用 JUnit 5 Vintage 运行 JUnit 4 测试。

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

例如:

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 junit5


    【解决方案1】:

    您可以使用 JUnit 5 Vintage 执行 JUnit 4 和 JUnit 5,

    通过导入 JUnit Vintage Engine 来使用它:

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-17
        • 2018-09-02
        • 2013-01-16
        • 1970-01-01
        • 2022-10-18
        • 2020-12-31
        • 2018-12-26
        • 1970-01-01
        相关资源
        最近更新 更多