JUnit5 套件忽略 class 名称中没有 "Test" 的测试

JUnit5 suite ignores tests without "Test" in class name

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

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

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

谁能告诉我如何让 junit 套件接受名称中没有 Test 的 classes 或如何配置它使用 IT 进行 class 检查?

我从 JUnit 团队那里得到了答案。

The @IncludeClassNamePatterns and @ExcludeClassNamePatterns annotations are designed explicitly for that purpose.

所以,

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