From: Curt S. <cj...@cy...> - 2002-03-22 11:38:25
|
On Thu, 21 Mar 2002, jay mistry wrote: > e.g i am testing a method: > void dispatchEvent(Event event) > which inside calls handleEvent(event) , in a class > called Handle A convenient way to think of a test is that the system starts out in one state and, after the test has run, should be in another, specific state. So at the beginning of the test you either put the system in the appropriate state or test that it's in that state already, and after executing the test code you examine the bits of state that are supposed to change, and verify that they have changed correctly. (You may also want to examine bits of the state that have not changed, and verify that they indeed have not changed.) Occasionally you will have to set up the test so that some state in the test itself changes state when certain actions happen. Usually this is done with stub and/or proxy objects. I'll give an example of this below. I can't really see from this description what change you're expecting in the system's state. What is supposed to be different after dispatchEvent is invoked? Going on what little information I can see here, if you wanted to test that dispatchEvent hands the event to an appropriate event handler, you could create a special test version of the event handler and event, and use these objects to do the test. It might look something like this: TestEventHandler handler = new TestEventHandler(); TestEvent event = new TestEvent(); dispatcher.register(handler); assertNull(handler.invokedWith(), "EventHandler not yet invoked."); dispatcher.dispatch(event); assertEquals(event, handler.invokedWith(), "EventHandler invoked with test event."); cjs -- Curt Sampson <cj...@cy...> +81 90 7737 2974 http://www.netbsd.org Don't you know, in this new Dark Age, we're all light. --XTC |