JUnit中的注释列表

最近,我研究并实现了JUnit框架。 因此,我知道在JUnit中使用的注释很少: – @Parameters @SuiteClasses({})@Parameters @SuiteClasses({})@Parameters @SuiteClasses({})@Parameters @SuiteClasses({})@Parameters @SuiteClasses({})@Parameters @SuiteClasses({})@Parameters @Runwith(Suite.class) @SuiteClasses({})@Parameters @SuiteClasses({})@Parameters@RunWith(Parameterized.class)@Rule

我确信在JUnit中有更多的注释。 任何人都可以用一个可以使用的更多注释列表以及在什么情况下使用它们来指导我?

谢谢。

这个Github搜索( @interface )为您提供了所有注释的列表:

https://github.com/junit-team/junit/search?q=%22%40interface%22&type=Code

基本注释

@Test @Before @After @AfterClass @BeforeClass @Ignore @Runwith

参数化测试

对于参数化测试,使用@Parameters@RunWith(Parameterized.class)
https://github.com/junit-team/junit/wiki/Parameterized-tests

类别

@Category
将测试分组。 例如快速,慢速等

https://github.com/junit-team/junit/wiki/Categories

@IncludeCategory
仅运行使用@IncludeCategory注释指定的类别或该类别的子类型注释的类和方法。

@ExcludeCategory
反向@IncludeCategory

规则

@Rule
规则允许非常灵活地添加或重新定义测试类中每个测试方法的行为。 例如,在运行测试时创建用于创建临时文件夹的临时文件夹规则。

https://github.com/junit-team/junit/wiki/Rules

理论和相关注释

@Theory
理论提供了更灵活和富有表现力的断言

https://github.com/junit-team/junit/wiki/Theories

@DataPoint
使用@DataPoint注释字段或方法将导致字段值或方法返回的值用作该类理论的潜在参数

@DataPoints

@Datapoint扩展
使用@DataPoints对数组或可迭代类型的字段或方法进行@DataPoints将导致数组中的值或给定的可迭代值被用作该类理论的潜在参数

@FromDataPoints

使用@Theory注释@Theory方法的参数会将被视为该参数的潜在值的数据点限制为仅具有给定名称的@DataPoints

@ParametersSuppliedBy
使用@Theory注释@Theory方法参数会导致在作为理论运行时从命名的ParameterSupplier提供值

@TestedOn

@TestedOn注释采用一组值作为带注释参数的数据点。

例如

 @Theory public void multiplyIsInverseOfDivideWithInlineDataPoints( @TestedOn(ints = {0, 5, 10}) int amount, @TestedOn(ints = {0, 1, 2}) int m ) { assumeThat(m, not(0)); assertThat(new Dollar(amount).times(m).divideBy(m).getAmount(), is(amount)); }