@Test 实际上做了什么?我有一些没有它的测试,它们运行良好。
我的课开始于
public class TransactionTest extends InstrumentationTestCase {
测试运行:
public void testGetDate() throws Exception {
或
@Test
public void testGetDate() throws Exception {
编辑:有人指出我可能正在使用 JUnit 3 测试,但我认为我正在使用 JUnit 4:
最佳答案
@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/