JUnit中的注释列表 [英] List of annotations in JUnit

查看:147
本文介绍了JUnit中的注释列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Recently, I have studied and implemented the JUnit framework. As a result i am aware of few annotations which are used in JUnit :- @Test, @Before, @After, @Ignore, @BeforeClass, @AfterClass, @Runwith(Suite.class), @SuiteClasses({}), @Parameters, @RunWith(Parameterized.class) and @Rule.

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

I am sure there are more annotations which are used in JUnit. Can anybody guide me with a list of more annotations that can be used and under what circumstances they are used?

谢谢。

推荐答案

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

This Github search (@interface) gives you the list of all the annotations :

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

@Test
@Before
@After
@Afte rClass
@BeforeClass
@Ignore
@Runwith

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

对于参数化测试,使用 @Parameters @RunWith(Parameterized.class)

https://github.com/junit-team/junit/wiki/Parameterized-tests

For Parameterized tests use @Parameters and @RunWith(Parameterized.class)
https://github.com/junit-team/junit/wiki/Parameterized-tests

@Category

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

@Category
Grouping tests into categories. e.g. Fast, Slow etc.

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

@IncludeCategory

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

@IncludeCategory
Runs only the classes and methods that are annotated with either the category given with the @IncludeCategory annotation, or a subtype of that category.

@ExcludeCategory

反向 @IncludeCategory

@Rule

规则允许非常灵活的添加或重新定义每种测试方法的行为一个测试类。例如创建临时文件夹规则以在运行测试时创建临时文件夹。

@Rule
Rules allow very flexible addition or redefinition of the behavior of each test method in a test class. e.g. Creating a Temp Folder rule for creating a temp folder while running tests.

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

@Theory

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

@Theory
Theories give more flexible and expressive assertions

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

@DataPoint

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

@DataPoint
Annotating an field or method with @DataPoint will cause the field value or the value returned by the method to be used as a potential parameter for theories in that class

@DataPoints

扩展 @Datapoint

使用 @DataPoints
注释数组或可迭代类型的字段或方法将导致数组中的值或给定的iterable值用作潜在的$ b该类理论的$ b参数

Extension of @Datapoint
Annotating an array or iterable-typed field or method with @DataPoints will cause the values in the array or iterable given to be used as potential parameters for theories in that class

@FromDataPoints

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

Annotating a parameter of a @Theory method with @FromDataPoints will limit the datapoints considered as potential values for that parameter to just the @DataPoints with the given name

@ParametersSuppliedBy

使用<$ c注释 @Theory 方法参数$ c> @ParametersSuppliedBy 使其在作为理论运行时从命名的 ParameterSupplier 提供

@ParametersSuppliedBy
Annotating a @Theory method parameter with @ParametersSuppliedBy causes it to be supplied with values from the named ParameterSupplier when run as a theory

@TestedOn

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

The @TestedOn annotation takes an array of values to be used as data points for the annotated parameter.

例如

@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));
}

这篇关于JUnit中的注释列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆