【问题标题】:JUnit5 suite ignores tests without "Test" in class nameJUnit5 套件忽略类名中没有“Test”的测试
【发布时间】:2020-09-18 12:26:38
【问题描述】:

我使用 junit5 并有两个带有集成测试的类 FooITTestBarIT。这是我的配置

@RunWith(JUnitPlatform.class)
@SelectClasses({ 
        FooIT.class, TestBarIT.class
})
@SuiteDisplayName("Suite IT")
public class SuiteIT { }

但是,如果我不添加单词 Test(例如 TestFooIT),FooIT 中的测试将被忽略。但我不想添加单词Test,因为我们对测试有严格的命名约定。

谁能说如何让junit套件接受名称中没有Test的类,或者配置它使用IT进行类检查?

【问题讨论】:

  • 请编辑您的问题,以包含有关如何使用您正在使用的所有库/框架运行单元测试的详细说明。

标签: java junit integration-testing junit5


【解决方案1】:

我从 JUnit 团队得到了答案。

@IncludeClassNamePatterns 和 @ExcludeClassNamePatterns 注释是专门为此目的而设计的。

所以,

@RunWith(JUnitPlatform.class)
@SelectClasses({ 
        FooIT.class, BarIT.class
})
@SuiteDisplayName("Suite IT")
@IncludeClassNamePatterns(".*IT$")
public class SuiteIT { }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 2017-07-14
    • 2022-01-14
    • 2020-04-14
    • 1970-01-01
    相关资源
    最近更新 更多