Re: TDD:ing MFC

"Phlip" <[email protected]> Thu, 14 Jun 2007 18:40:23 -0700
Newsgroups gmane.comp.programming.test-driven-development,gmane.comp.programming.test-first-user-interfaces
Message-ID <01d901c7aeee$26f442a0$6601a8c0@Marley>
Paula S. wrote:

> I know some people are successfully doing TDD with VC++ MFC. I'm currently 
> trying to add unit tests to a legacy MFC application and need some help to 
> get started testing dialogs and windows. Some pointers in the right 
> direction would be much appreciated.

MFC has major architectural flaws that resist clean testing. One good policy 
is to use "in vivo" testing, per the book /Working Effictively with Legacy 
Code/ by Mike Feathers. That means you start the application's main work 
loop, and after the main window has painted you encounter a line of code 
like this:

#ifdef DEBUG
      runTests(mainHwnd);
#end

That means when you run your program from VC++, in Debug mode it will invoke 
a test rig, and pass in a handle to the main window. The tests now operate 
on the window, treating all its subwindows and controls as objects.

I would use UnitTest++ for the test rig. It's designed to be lean and 
non-invasive (unlike MFC), so you'll easily squeeze it into the runTests() 
function.

Ask about any more questions!

-- 
  Phlip
  http://www.oreilly.com/catalog/9780596510657/
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/testdrivendevelopment/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/testdrivendevelopment/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/