JUnit5套件会忽略类名中没有“Test”的测试。

huangapple go评论66阅读模式
英文:

JUnit5 suite ignores tests without "Test" in class name

问题

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

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

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

有没有人可以说明如何使 junit 套件接受没有在类名中添加 Test 的类,或者如何配置它来使用 IT 进行类检查?

英文:

I use junit5 and have two classes with integrations tests FooIT and TestBarIT. This is my configuration

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

However, tests in FooIT will be ignored if I don't add word Test (for example TestFooIT). But I don't want to add word Test as we have a strict naming convention for tests.

Can anyone say how to make junit suite accept classes without Test in their names or to configure it use IT for class checking?

答案1

得分: 2

我从JUnit团队得到了答复。

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

因此,

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

I got the answer from JUnit team.

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

So,

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

huangapple
  • 本文由 发表于 2020年9月18日 20:26:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63955768.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定