Test driven development (TDD) is one of the central techniques in Extreme Programming. However many people dismiss it for GUI applications because it seems to be too hard to get the user interface code under test. This presentation is about how to apply TDD to GUI applications.
22. TDD for GUIs
• GUI Code hard to test
therefore
• Isolate GUI Code
• Keep complexity low
Dienstag, 9. Juni 2009
23. Model-View-Controller (MVC)
Controller
User Event Update State Change
Change Notification
View Model
State Query
Dienstag, 9. Juni 2009 Zustand lesen
24. Model-View-Presenter (MPV)
User Event Change Notification
View Presenter Model
Update State Query/Change
Dienstag, 9. Juni 2009 Zustand lesen
27. Model (State Machine)
• States
• Number
• Wait for Number
• Error
• Properties
• State
• Input
• Value
• Error Message
• Memory
• Operation
• Methods
• Read Token
Dienstag, 9. Juni 2009
28. Presenter
View Model
P
• Properties
r
• Properties
e • State
• Display
s • Input
• Memory e • Value
n • Error Message
• Operation
t • Memory
• Events e • Operation
r • Methods
• Button press
• Read Token
Dienstag, 9. Juni 2009
29. Testing the Presenter
PresenterTest
ViewMock Presenter ModelMock
Dienstag, 9. Juni 2009 Zustand lesen
33. Test the „wiring“
• Test the API used by the Presenter
• There is a lot testable code in the view
Dienstag, 9. Juni 2009
34. Testing the Events
• Test just below the „native“ events
• Simulate „native“ events
Dienstag, 9. Juni 2009
35. Testing the Look & Feel
• Themes are code, too
• It‘s impossible to automatically test the
look
BUT
• View has few dependencies
• View can be run in isolation
Dienstag, 9. Juni 2009
41. Resources / TDD
• Literature
• „Test Driven Development by Example“, Kent Beck
• „Working Effectively with Legacy Code“, Michael
Feathers
• „Clean Code: A Handbook of Agile Software
Craftsmanship“, Robert C. Martin
• Online-presentations
• „Test Driven Development?“, Frederik Kalseth
http://iridescence.no/post/Slides-From-my-TDD-
Talk.aspx
• „Test Driven Development Best Practices for
Eclipse RCP“, Kevin Taylor, http://live.eclipse.org/
node/700
Dienstag, 9. Juni 2009
42. Resources / MVP
• Martin Fowler
• Passive View, http://www.martinfowler.com/eaaDev/
PassiveScreen.html
• GUI Architectures, http://www.martinfowler.com/eaaDev/
uiArchs.html
• Microsoft
• View Testability, http://msdn.microsoft.com/en-us/library/
cc304742.aspx
• Design Patterns - Model View Presenter, http://
msdn.microsoft.com/de-de/magazine/cc188690(en-us).aspx
• „Build Your Own CAB“, Jeremey D. Miller, http://
codebetter.com/blogs/jeremy.miller/archive/2007/07/25/the-
build-your-own-cab-series-table-of-contents.aspx
Dienstag, 9. Juni 2009