testing - JUnit 4 @Test 注释实际上做了什么

标签 testing junit junit4

@Test 实际上做了什么?我有一些没有它的测试,它们运行良好。

我的课开始于

public class TransactionTest extends InstrumentationTestCase {

测试运行:

public void testGetDate() throws Exception {

@Test
public void testGetDate() throws Exception {

编辑:有人指出我可能正在使用 JUnit 3 测试,但我认为我正在使用 JUnit 4:

enter image description here

最佳答案

@Test 
public void method()

@Test => annotation identifies a method as a test method.
@Test(expected = Exception.class) => Fails if the method does not throw the named exception.
@Test(timeout=100)  =>  Fails if the method takes longer than 100 milliseconds.

@Before 
public void method() =>This method is executed before each test. It is used to prepare the test environment (e.g., read input data, initialize the class).

@After 
public void method() => This method is executed after each test. It is used to cleanup the test environment (e.g., delete temporary data, restore defaults). It can also save memory by cleaning up expensive memory structures.

@BeforeClass 
public static void method() => This method is executed once, before the start of all tests. It is used to perform time intensive activities, for example, to connect to a database. Methods marked with this annotation need to be defined as static to work with JUnit.

@AfterClass 
public static void method() =>  This method is executed once, after all tests have been finished. It is used to perform clean-up activities, for example, to disconnect from a database. Methods annotated with this annotation need to be defined as static to work with JUnit.

@Ignore => Ignores the test method. This is useful when the underlying code has been changed and the test case has not yet been adapted. Or if the execution time of this test is too long to be included.

关于testing - JUnit 4 @Test 注释实际上做了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29419287/

相关文章:

java - H2 数据库 org.h2.Driver ClassNotFoundException

junit4 - 如何在没有@RunWith 注释的情况下运行 JUnit 5 套件

java - 我可以对多个测试类使用相同的参数化数据吗

python - 编写测试运行程序时是否可以进行 TDD?

支持原生模块的 JavaScript 测试运行器

visual-studio-2010 - 编码的 UI 错误 : The following element is not longer availabe

java - 方法实例化与类级实例化的 junit 测试

testing - 简单模拟 - 如何?

ruby-on-rails - Rails Rake 测试 : Errors running test:units! #<RuntimeError: 命令失败,状态为

android - Android Junit 项目中的日志记录和 Junit 测试问题