Re: [TFUI] Dialogs and EventHandlers
Ed Howland <[email protected]> Mon, 7 Nov 2005 08:37:15 -0600
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Message-ID | <[email protected]> |
On 11/7/05, Anthony Williams <anthony_w.geo-/[email protected]> wrote: > > I just posted an entry on my blog about this, describing what I would do > differently: > > http://www.livejournal.com/users/anthony_w/8000.html > > The key difference is that I believe the GetFontFromUserSelection function > does not belong on the MyForm class, so I would extract it to a collaborator > instead of mocking the FontDialog. > > Anthony Hi Anthony, Two points about your approach. I notice your form.menuItem15_Click(null, null); is still private on your MyForm class. And you should be able to mock with NMock or the built in DynamicMock in NUnit in your test. DynamicMock mock = new DynamicMock(typeof(FontSelector); MyForm form = new MyForm((FontSelector)mock); mock.ExpectAndReturn("GetFontFromUserSelection", expectedFont, defaultFont); ... form.menuItem15_Click(null, null); mock.Verify() Assert.AreEqual(expectedFont, form.Display.Font); This has the advantage of not needing another class (MockFontSelector.) And you can easily test the wiring across the seam, as it were (via Verify()) Other than that, your point of extracting to a collaborator class is very good. And it has the extra benefits of being more testable itself and being reusable. I've heard it said that the code should treat UI elements as if it were calling the human API. Each time we suspend and await human interaction (as in the case of the forn dialog here,) we are actually just calling the human library function (getFontFromHuman().) Creating seams around these various steps makes them easier to automate w/o having to resort to a UI robot tester. Ed ------------------------ Yahoo! Groups Sponsor --------------------~--> Most low income households are not online. Help bridge the digital divide today! http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/nhFolB/TM --------------------------------------------------------------------~-> To unsubscribe, email: TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/TestFirstUserInterfaces/ <*> To unsubscribe from this group, send an email to: TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/