SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
TDD for
                              User Interfaces

                         Fabian Jakobs <fabian.jakobs@1und1.de>
                           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

            Good Design                                Testable


                                        Modular



                             Few                  Extensible
                         Dependencies


Dienstag, 9. Juni 2009
That Works


                         Fast
                                                    In Time

                                      Satisfies
                                    Requirements


                          Robust                   Happy
                                                   Users



Dienstag, 9. Juni 2009
Write          Use

                                 Code




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
Red


                                  What do I expect
                                   from the code



                                Write Test

                         Code




Dienstag, 9. Juni 2009
Green

                         „Make the test pass with the
                           easiest code possible!“



Dienstag, 9. Juni 2009
Green

                          What is the
                         easiest code to
                          make the test
                              pass?



                                   Write

                                            Code




Dienstag, 9. Juni 2009
Refactor

                             „Remove all duplication
                         introduced by making the test
                                    pass!“



Dienstag, 9. Juni 2009
Refactor


                         I have to remove
                            duplication!



                                    Write

                                              Code




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
                                        therefore

                          • Isolate GUI Code
                          • Keep complexity low

Dienstag, 9. Juni 2009
Model-View-Controller (MVC)



                                             Controller

                         User Event      Update                  State Change




                                            Change Notification
                            View                                   Model
                                                  State Query




Dienstag, 9. Juni 2009   Zustand lesen
Model-View-Presenter (MPV)




                               User Event               Change Notification


                 View                       Presenter                        Model

                                 Update                 State Query/Change




Dienstag, 9. Juni 2009   Zustand lesen
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
                            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
Testing the Presenter

                                         PresenterTest




          ViewMock                        Presenter      ModelMock



Dienstag, 9. Juni 2009   Zustand lesen
Testing the Presenter
                                         PresenterTest




Dienstag, 9. Juni 2009   Zustand lesen
Testing Events
                                          PresenterTest




                                                            ModelMock
                         ViewMock
                                                Presenter




Dienstag, 9. Juni 2009    Zustand lesen
How to test the view?



Dienstag, 9. Juni 2009
Test the „wiring“

                         • Test the API used by the Presenter
                         • There is a lot testable code in the view




Dienstag, 9. Juni 2009
Testing the Events

                         • Test just below the „native“ events
                         • Simulate „native“ events




Dienstag, 9. Juni 2009
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
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

Weitere ähnliche Inhalte

Andere mochten auch

Cp tbwa corporate cristal festival
Cp tbwa corporate cristal festivalCp tbwa corporate cristal festival
Cp tbwa corporate cristal festivalTBWA\Corporate
 
Cotabox - Novembro 2015
Cotabox - Novembro 2015Cotabox - Novembro 2015
Cotabox - Novembro 2015Fernando Tomé
 
Пациент П.С.Н.
Пациент П.С.Н.Пациент П.С.Н.
Пациент П.С.Н.gtuni
 
Property, Plant and Equipment
Property, Plant and EquipmentProperty, Plant and Equipment
Property, Plant and EquipmentMarielMerc
 
O型人飲食的探討:
O型人飲食的探討:O型人飲食的探討:
O型人飲食的探討:yct.Ken Chang
 
Ericsson ConsumerLab: Internet goes mobile - Nigeria
Ericsson ConsumerLab: Internet goes mobile - NigeriaEricsson ConsumerLab: Internet goes mobile - Nigeria
Ericsson ConsumerLab: Internet goes mobile - NigeriaEricsson
 
The Power of Social Media for Dentists
The Power of Social Media for DentistsThe Power of Social Media for Dentists
The Power of Social Media for DentistsNicole Stagg
 
Top 10 Quotes About Editing
Top 10 Quotes About EditingTop 10 Quotes About Editing
Top 10 Quotes About EditingScribendi
 
11 Ridiculous Things You Could Buy With Your Student Debt
11 Ridiculous Things You Could Buy With Your Student Debt11 Ridiculous Things You Could Buy With Your Student Debt
11 Ridiculous Things You Could Buy With Your Student DebtMashable
 
Bennett Higher education employability keynote Criterion May 2016
Bennett Higher education employability keynote Criterion May 2016Bennett Higher education employability keynote Criterion May 2016
Bennett Higher education employability keynote Criterion May 2016Dawn Bennett
 
How Effective is the Combination of your Main Product....
How Effective is the Combination of your Main Product....How Effective is the Combination of your Main Product....
How Effective is the Combination of your Main Product....Chloe Ambrose
 
What it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannes
What it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannesWhat it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannes
What it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannesOgilvy
 
20151015 earthsimulationoceanusoct
20151015 earthsimulationoceanusoct20151015 earthsimulationoceanusoct
20151015 earthsimulationoceanusoctAnselm Hook
 

Andere mochten auch (13)

Cp tbwa corporate cristal festival
Cp tbwa corporate cristal festivalCp tbwa corporate cristal festival
Cp tbwa corporate cristal festival
 
Cotabox - Novembro 2015
Cotabox - Novembro 2015Cotabox - Novembro 2015
Cotabox - Novembro 2015
 
Пациент П.С.Н.
Пациент П.С.Н.Пациент П.С.Н.
Пациент П.С.Н.
 
Property, Plant and Equipment
Property, Plant and EquipmentProperty, Plant and Equipment
Property, Plant and Equipment
 
O型人飲食的探討:
O型人飲食的探討:O型人飲食的探討:
O型人飲食的探討:
 
Ericsson ConsumerLab: Internet goes mobile - Nigeria
Ericsson ConsumerLab: Internet goes mobile - NigeriaEricsson ConsumerLab: Internet goes mobile - Nigeria
Ericsson ConsumerLab: Internet goes mobile - Nigeria
 
The Power of Social Media for Dentists
The Power of Social Media for DentistsThe Power of Social Media for Dentists
The Power of Social Media for Dentists
 
Top 10 Quotes About Editing
Top 10 Quotes About EditingTop 10 Quotes About Editing
Top 10 Quotes About Editing
 
11 Ridiculous Things You Could Buy With Your Student Debt
11 Ridiculous Things You Could Buy With Your Student Debt11 Ridiculous Things You Could Buy With Your Student Debt
11 Ridiculous Things You Could Buy With Your Student Debt
 
Bennett Higher education employability keynote Criterion May 2016
Bennett Higher education employability keynote Criterion May 2016Bennett Higher education employability keynote Criterion May 2016
Bennett Higher education employability keynote Criterion May 2016
 
How Effective is the Combination of your Main Product....
How Effective is the Combination of your Main Product....How Effective is the Combination of your Main Product....
How Effective is the Combination of your Main Product....
 
What it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannes
What it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannesWhat it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannes
What it Takes to Make a Moonshot—via Google[X] / #CannesLions #OgilvyCannes
 
20151015 earthsimulationoceanusoct
20151015 earthsimulationoceanusoct20151015 earthsimulationoceanusoct
20151015 earthsimulationoceanusoct
 

Mehr von Fabian Jakobs

Amsterdam.js talk: node webkit
Amsterdam.js talk: node webkitAmsterdam.js talk: node webkit
Amsterdam.js talk: node webkitFabian Jakobs
 
Bespin, Skywriter, Ace The Past, Present and Future of online Code Editing
Bespin, Skywriter, Ace The Past, Present and Future of online Code EditingBespin, Skywriter, Ace The Past, Present and Future of online Code Editing
Bespin, Skywriter, Ace The Past, Present and Future of online Code EditingFabian Jakobs
 
Kick ass code editing and end to end JavaScript debugging
Kick ass code editing and end to end JavaScript debuggingKick ass code editing and end to end JavaScript debugging
Kick ass code editing and end to end JavaScript debuggingFabian Jakobs
 
Masterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsFabian Jakobs
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedFabian Jakobs
 
Qooxdoo 0.8 - Das Neue Gui Toolkit
Qooxdoo 0.8 - Das Neue Gui ToolkitQooxdoo 0.8 - Das Neue Gui Toolkit
Qooxdoo 0.8 - Das Neue Gui ToolkitFabian Jakobs
 
Ajax In Action 2008 - Gui Development With qooxdoo
Ajax In Action 2008 - Gui Development With qooxdooAjax In Action 2008 - Gui Development With qooxdoo
Ajax In Action 2008 - Gui Development With qooxdooFabian Jakobs
 
DLW Europe - JavaScript Tooling
DLW Europe - JavaScript ToolingDLW Europe - JavaScript Tooling
DLW Europe - JavaScript ToolingFabian Jakobs
 

Mehr von Fabian Jakobs (11)

Amsterdam.js talk: node webkit
Amsterdam.js talk: node webkitAmsterdam.js talk: node webkit
Amsterdam.js talk: node webkit
 
Bespin, Skywriter, Ace The Past, Present and Future of online Code Editing
Bespin, Skywriter, Ace The Past, Present and Future of online Code EditingBespin, Skywriter, Ace The Past, Present and Future of online Code Editing
Bespin, Skywriter, Ace The Past, Present and Future of online Code Editing
 
Kick ass code editing and end to end JavaScript debugging
Kick ass code editing and end to end JavaScript debuggingKick ass code editing and end to end JavaScript debugging
Kick ass code editing and end to end JavaScript debugging
 
Autopsy Of A Widget
Autopsy Of A WidgetAutopsy Of A Widget
Autopsy Of A Widget
 
Masterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script Applications
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
 
Going Virtual
Going VirtualGoing Virtual
Going Virtual
 
Going Virtual
Going VirtualGoing Virtual
Going Virtual
 
Qooxdoo 0.8 - Das Neue Gui Toolkit
Qooxdoo 0.8 - Das Neue Gui ToolkitQooxdoo 0.8 - Das Neue Gui Toolkit
Qooxdoo 0.8 - Das Neue Gui Toolkit
 
Ajax In Action 2008 - Gui Development With qooxdoo
Ajax In Action 2008 - Gui Development With qooxdooAjax In Action 2008 - Gui Development With qooxdoo
Ajax In Action 2008 - Gui Development With qooxdoo
 
DLW Europe - JavaScript Tooling
DLW Europe - JavaScript ToolingDLW Europe - JavaScript Tooling
DLW Europe - JavaScript Tooling
 

Tdd For GuIs

  • 1. TDD for User Interfaces Fabian Jakobs <fabian.jakobs@1und1.de> qooxdoo Team <http://qooxdoo.org> Dienstag, 9. Juni 2009
  • 2. Agenda • What is Test Driven Development? • TDD for user interfaces • Example Dienstag, 9. Juni 2009
  • 4. „Clean code that works“ Ron Jeffrie Dienstag, 9. Juni 2009
  • 5. Clean Code Good Design Testable Modular Few Extensible Dependencies Dienstag, 9. Juni 2009
  • 6. That Works Fast In Time Satisfies Requirements Robust Happy Users Dienstag, 9. Juni 2009
  • 7. Write Use Code Dienstag, 9. Juni 2009
  • 8. TDD Mantra •Red • Green • Refactor Dienstag, 9. Juni 2009
  • 9. Red „Don‘t write production code unless to make a failing test pass!“ Dienstag, 9. Juni 2009
  • 10. Red What do I expect from the code Write Test Code Dienstag, 9. Juni 2009
  • 11. Green „Make the test pass with the easiest code possible!“ Dienstag, 9. Juni 2009
  • 12. Green What is the easiest code to make the test pass? Write Code Dienstag, 9. Juni 2009
  • 13. Refactor „Remove all duplication introduced by making the test pass!“ Dienstag, 9. Juni 2009
  • 14. Refactor I have to remove duplication! Write Code Dienstag, 9. Juni 2009
  • 15. „Edit and Pray“ vs. „Cover and Modify“ Michael Feathers Dienstag, 9. Juni 2009
  • 16. Edit & Pray • Carefully plan • Make the change • Start the application and check the change • Poking aroud Dienstag, 9. Juni 2009
  • 17. Cover & Modify • Write test • Make the change • Run all tests Dienstag, 9. Juni 2009
  • 18. Tests give confidence in the code. „I better don‘t touch this area of the code“ Dienstag, 9. Juni 2009
  • 19. Tests are dokumentation „Every test is an executable example.“ Dienstag, 9. Juni 2009
  • 20. Tests guide the design „We see the code from the user‘s perspective“ Dienstag, 9. Juni 2009
  • 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
  • 26. View • Properties • Display • Memory • Operation • Events • Button press Dienstag, 9. Juni 2009
  • 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
  • 30. Testing the Presenter PresenterTest Dienstag, 9. Juni 2009 Zustand lesen
  • 31. Testing Events PresenterTest ModelMock ViewMock Presenter Dienstag, 9. Juni 2009 Zustand lesen
  • 32. How to test the view? Dienstag, 9. Juni 2009
  • 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
  • 37. Conclusion TDD can be applied to GUI code if the architecture is right. Dienstag, 9. Juni 2009
  • 38. „Legacy code is code without tests“ Michael Feathers Dienstag, 9. Juni 2009
  • 40. Resources - Code git clone git://github.com/fjakobs/Calculator.git 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