Re: [TFUI] Dialogs and EventHandlers
Hristo Deshev <[email protected]> Fri, 4 Nov 2005 21:44:20 +0200
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Message-ID | <[email protected]> |
Hi Cory, Nice post and a nice blog. I added it to my Bloglines list :). On 11/4/05, Cory Foy <[email protected]> wrote: > > Hi All, > I'd love you have your feedback on if this would have been the approach > you would have taken and anything else I could have done differently: > > > http://www.cornetdesign.com/2005/11/writing-tests-for-private-void-classes.html This whole factory and configuration thing looks a bit too much to me. I usually do a thing, Michael Feathers calls "Subclass and override" in his Working Effectively with Legacy Code book. I pulled the FontDialog creation from your code in a separate method: protected virtual IFontDialog CreateFontDialog() { return new TestableFontDialog(); } and overrode that in a testing subclass: protected override IFontDialog CreateFontDialog() { return new MockFontDialog(); } My test then becomes (note the use of TestingEditorForm): [Test] public void UserSelectionOfANewFontShouldChangeTheDisplayFont() { MockFontDialog dialog = new MockFontDialog(); dialog.Font = new Font("Times New Roman", 14); EditorForm editor = new TestingEditorForm(); editor.fontButton_Click(null, null); Font expectedFont = new Font("Times New Roman", 14); Assert.AreEqual(expectedFont, editor.Display.Font); } I renamed MyFontDialog to TestableFontDialog. I took the name from Ron Jeffries' Adventures in C# book where he does a similar thing to a TextBox. You know, I recently finished reading Michael Feathers' book and your post reminds me of it. The techniques you use to get rid of the modal dialog in the tests are similar to the ones described in the book. I normally work in an ASP.NET <http://ASP.NET> environment, but the techniques are applicable there too (It's just that we don't have modal dialogs there, only hard to create objects like System.Web.HttpContext). Hristo Deshev http://blogs.telerik.com/blogs/twisted_asp_net/ [Non-text portions of this message have been removed] ------------------------ 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/