Tdd For GuIs
-
Upload
fabian-jakobs -
Category
Technology
-
view
3.519 -
download
2
description
Transcript of Tdd For GuIs
TDD forUser Interfaces
Fabian Jakobs <[email protected]>qooxdoo Team <http://qooxdoo.org>
Dienstag, 9. Juni 2009
Agenda
• What is Test Driven Development?
• TDD for user interfaces
• Example
Dienstag, 9. Juni 2009
TDD
Dienstag, 9. Juni 2009
„Clean code that works“
Ron Jeffrie
Dienstag, 9. Juni 2009
Clean Code
FewDependencies
Modular
Good Design
Extensible
Testable
Dienstag, 9. Juni 2009
That Works
SatisfiesRequirements
Fast
Robust
In Time
HappyUsers
Dienstag, 9. Juni 2009
CodeWrite Use
Dienstag, 9. Juni 2009
TDD Mantra
• Red
• Green
• Refactor
Dienstag, 9. Juni 2009
Red
„Don‘t write production code unless to make a failing test pass!“
Dienstag, 9. Juni 2009
CodeWrite Test
What do I expect from the code
Red
Dienstag, 9. Juni 2009
Green
„Make the test pass with the easiest code possible!“
Dienstag, 9. Juni 2009
CodeWrite
What is the easiest code to make the test
pass?
Green
Dienstag, 9. Juni 2009
Refactor
„Remove all duplication introduced by making the test
pass!“
Dienstag, 9. Juni 2009
CodeWrite
I have to remove duplication!
Refactor
Dienstag, 9. Juni 2009
„Edit and Pray“vs.
„Cover and Modify“Michael Feathers
Dienstag, 9. Juni 2009
Edit & Pray
• Carefully plan
• Make the change
• Start the application and check the change
• Poking aroud
Dienstag, 9. Juni 2009
Cover & Modify
• Write test
• Make the change
• Run all tests
Dienstag, 9. Juni 2009
Tests give confidence in the code.
„I better don‘t touch this area of the code“
Dienstag, 9. Juni 2009
Tests are dokumentation
„Every test is an executable example.“
Dienstag, 9. Juni 2009
Tests guide the design
„We see the code from the user‘s perspective“
Dienstag, 9. Juni 2009
Testing GUIs
Dienstag, 9. Juni 2009
TDD for GUIs
• GUI Code hard to test
• Isolate GUI Code
• Keep complexity low
therefore
Dienstag, 9. Juni 2009
Model-View-Controller (MVC)
Model
Controller
State Change
State Query
View
Zustand lesen
Change Notification
UpdateUser Event
Dienstag, 9. Juni 2009
Model-View-Presenter (MPV)
ModelPresenterView
Zustand lesen
State Query/Change
Change Notification
Update
User Event
Dienstag, 9. Juni 2009
Example
Dienstag, 9. Juni 2009
View
• Properties
• Display
• Memory
• Operation
• Events
• Button press
Dienstag, 9. Juni 2009
Model (State Machine)
• States
• Number
• Wait for Number
• Error
• Properties
• State
• Input
• Value
• Error Message
• Memory
• Operation
• Methods
• Read Token
Dienstag, 9. Juni 2009
Presenter
• Properties
• State
• Input
• Value
• Error Message
• Memory
• Operation
• Methods
• Read Token
• Properties
• Display
• Memory
• Operation
• Events
• Button press
Presenter
ModelView
Dienstag, 9. Juni 2009
Testing the Presenter
ModelMockPresenterViewMock
Zustand lesen
PresenterTest
Dienstag, 9. Juni 2009
PresenterTest
Zustand lesen
Testing the Presenter
Dienstag, 9. Juni 2009
Testing Events
Zustand lesen
ModelMockViewMock
Presenter
PresenterTest
Dienstag, 9. Juni 2009
How to test the view?
Dienstag, 9. Juni 2009
• Test the API used by the Presenter
• There is a lot testable code in the view
Test the „wiring“
Dienstag, 9. Juni 2009
• Test just below the „native“ events
• Simulate „native“ events
Testing the Events
Dienstag, 9. Juni 2009
• Themes are code, too
• It‘s impossible to automatically test the look
• View has few dependencies
• View can be run in isolation
Testing the Look & Feel
BUT
Dienstag, 9. Juni 2009
Mini-Programs
Dienstag, 9. Juni 2009
Conclusion
TDD can be applied to GUI code if the architecture is right.
Dienstag, 9. Juni 2009
„Legacy code is code without tests“
Michael Feathers
Dienstag, 9. Juni 2009
Questions?
Dienstag, 9. Juni 2009
Resources - Code
git clone git://github.com/fjakobs/Calculator.git
Dienstag, 9. Juni 2009
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
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