Fastpoint
级别: 总版主
精华:
44
发帖: 5033
基地声望: 390 点
基地币: 1689 Bug
基地贡献: 0 点
好评度: 15 点
在线时间:818(小时)
注册时间:2005-10-08
最后登录:2008-07-22
|
[FAQ]JUnit的测试执行程序流程
引用Kent Beck, Erich Gamma,连接地址:http://junit.sourceforge.net/doc/cookbook/cookbook.htm
A test fixture is useful if you have two or more tests for a common set of objects. Using a test fixture avoids duplicating the test code necessary to initialize and cleanup those common objects for each test.
Tests can use the objects (variables) in a test fixture, with each test invoking different methods on objects in the fixture and asserting different expected results. Each test runs in its own test fixture to isolate tests from the changes made by other tests. That is, tests don't share the state of objects in the test fixture. Because the tests are isolated, they can be run in any order.
To create a test fixture, define a setUp() method that initializes common objects and a tearDown() method to cleanup those objects. The JUnit framework automatically invokes the setUp() method before each test is run and the tearDown() method after each test is run.
The following test uses a test fixture to initialize and cleanup a common Collection object such that both tests are isolated from changes made by the other:
package junitfaq;
import junit.framework.*; import java.util.*; public class SimpleTest extends TestCase { private Collection collection; protected void setUp() { collection = new ArrayList(); } protected void tearDown() { collection.clear(); }
public void testEmptyCollection() { assertTrue(collection.isEmpty()); } public void testOneItemCollection() { collection.add("itemA"); assertEquals(1, collection.size()); } }
Given this test, the methods might execute in the following order:
setUp() testOneItemCollection() tearDown() setUp() testEmptyCollection() tearDown()
The ordering of test-method invocations is not guaranteed, so testEmptyCollection() might be executed before testOneItemCollection(). This is why the test methods themselves must be written to be independent of one another. What is guaranteed is that setUp() will execute before each test method and tearDown() will execute after each test method.
[ 此贴被Fastpoint在2005-10-17 11:08重新编辑 ]
|
可不可不要这么样徘徊在目光内 你会察觉到我根本寂寞难耐 即使千多百个深夜曾在梦境内 我有吻过你这毕竟并没存在
人声车声开始消和逝 无声挣扎有个情感奴隶 是我多么的想她 但我偏偏只得无尽叹谓
其实每次见你我也着迷 无奈你我各有角色范围 就算在寂寞梦内超出好友关系 唯在暗里爱你暗里着迷 无谓要你惹上各种问题 共我道别吧别让空虚使我越轨
|
|
[楼 主]
|
Posted: 2005-10-14 19:48 |
| |