Re: [TFUI] Dialogs and EventHandlers
Anthony Williams <anthony_w.geo-/[email protected]> Mon, 07 Nov 2005 15:07:44 +0000
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Organization | Just Software Solutions Ltd |
| Message-ID | <[email protected]> |
Ed Howland <[email protected]> writes: > 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. > 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()) Absolutely. I left the implementation of MockFontSelector as an exercise for the reader, since it's not really relevant to the idea. If you generally use a mocking framework such as NMock, then it would make sense to use it here; if you generally hand-craft your mocks, then I would suggest you do the same here. Anthony -- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk ------------------------ Yahoo! Groups Sponsor --------------------~--> Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life. http://us.click.yahoo.com/A77XvD/vlQLAA/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/