Annotations in JUnit
来源:互联网 发布:招聘node 编辑:程序博客网 时间:2024/05/18 03:02
http://www.devmanuals.com/tutorials/java/JavaTestingTools/junit/AnnotationsInJUnit.html
https://github.com/junit-team/junit/wiki/Getting-started
Annotations are like meta-tags that you can add to you code and apply them to methods or in class. These annotation in JUnit gives us information about test methods , which methods are going to run before & after test methods, which methods run before & after all the methods, which methods or class will be ignore during execution, which methods are suspected to throw exception etc.
Annotation are added in JUnit 4 version & you can found it in all the releases after this version. Annotations reduces coding & extra burden from tester. The annotations in JUnit are predefined and need not to define, you can implement it directly. Also you can have your own defined annotations in class. But for testing , annotations are predefined in JUnit.
Notes
All test methods are annotated with @Test. Unlike JUnit3 tests, you do not need to prefix the method name with "test" (and usually don't)
Do not have your test classes extend junit.framework.TestCase (directly or indirectly). Usually, tests with JUnit4 do not need to extend anything (which is good, since Java does not support multiple inheritance)
Do not use any classes in junit.framework or junit.extensions
Given below list of annotations and their meaning in JUnit :
AnnotationDescription@Test
The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case.
@Before
Several tests need similar objects created before they can run. Annotating a public void method with @Before causes that method to be run before each Test method.
@After
If you allocate external resources in a Before method you need to release them after the test runs. Annotating a public void method with @After causes that method to be run after the Test method.
@BeforeClass
Annotating a public static void method with @BeforeClass causes it to be run once before any of the test methods in the class. This can be used to perform computationally expensive setup (like logging into a database).
@AfterClass
Will perform the method after all tests have finished. This can be used to perform clean-up activities for example be used to disconnect to a database
@Ignore
Sometimes you want to temporarily disable a test or a group of tests. Methods annotated with Test that are also annotated with @Ignore will not be executed as tests. Also, you can annotate a class containing test methods with @Ignore and none of the containing tests will be executed.
- Annotations in JUnit
- Annotations in Tiger, Part 2: Custom annotations
- Junit (Assertions in JUNIT)
- Junit 4 Core Concept [1] Annotations
- Create multiple annotations in Plist
- Annotations
- Annotations
- Commons-Attributes vs annotations in Java 5.0
- Multi-Column Join in Hibernate/JPA Annotations
- Get field class in annotations processor
- use Mix-In Annotations to reuse, decouple
- JUnit In Action 笔记
- 《JUnit in action》
- Mock in JUnit
- JUnit in Action
- Unit Testing in JUnit
- junit in action读书笔记
- JUnit in android
- 基于SSH2框架Struts2拦截器的登录验证实现
- java泛型相关经验总结
- 基于SSH2框架AspectJ的登录登出日志实现
- Fedora18设置终端快捷键 和 桌面快捷方式
- jQuery验证控件jquery.validate.js使用说明+中文API
- Annotations in JUnit
- 寻找最大的K个数
- TS数据结构分析
- HDU2389 Rain on your Parade 二分匹配 Hopcroft-Carp的算法+模版
- 牙膏小常识 你知道不?
- 关于循环最后一步特殊处理的算法
- 解析XML的几种方法
- 迷茫
- Transact-SQL编程