Behavior Driven Development<br />Vermont<br />Code Camp<br />September 11, 2010<br />By Tom Cooley<br />
Tom Cooley<br /><ul><li>Principal Software Architect at MyWebGrocer
Developer for 20+ years
C# for 7+ years
Primary focus includes:
Object-oriented architecture
Design patterns and principles
Database development/DBA for 14+ years
Co-leader of VT SQL Server user group
Member of International Association of Software Architects
Presenter at VT .NET and VT SQL Server user groups</li></li></ul><li>Session Overview<br /><ul><li>Why is testing so hard?
BDD Overview
The Ubiquitous Language of BDD
Upcoming SlideShare
Loading in …5
×

Behavior Driven Development

1,180 views
1,119 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,180
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Behavior Driven Development

  1. 1. Behavior Driven Development<br />Vermont<br />Code Camp<br />September 11, 2010<br />By Tom Cooley<br />
  2. 2. Tom Cooley<br /><ul><li>Principal Software Architect at MyWebGrocer
  3. 3. Developer for 20+ years
  4. 4. C# for 7+ years
  5. 5. Primary focus includes:
  6. 6. Object-oriented architecture
  7. 7. Design patterns and principles
  8. 8. Database development/DBA for 14+ years
  9. 9. Co-leader of VT SQL Server user group
  10. 10. Member of International Association of Software Architects
  11. 11. Presenter at VT .NET and VT SQL Server user groups</li></li></ul><li>Session Overview<br /><ul><li>Why is testing so hard?
  12. 12. BDD Overview
  13. 13. The Ubiquitous Language of BDD
  14. 14. The BDD Story
  15. 15. Specifications
  16. 16. Tools and toys
  17. 17. and of course…demo code</li></li></ul><li>Unit Testing<br />The good, the bad, the ugly<br />
  18. 18. Evolution of TDD Learning and Adoption<br />The developer starts writing unit tests around their code using a test framework like JUnit or NUnit. <br />As the body of tests increases the developer begins to enjoy a strongly increased sense of confidence in their work. <br />At some point the developer has the insight (or is shown) that writing the tests before writing the code, helps them to focus on writing only the code that they need. <br />The developer also notices that when they return to some code that they haven't seen for a while, the tests serve to document how the code works. <br />A point of revelation occurs when the developer realizes that writing tests in this way helps them to “discover” the API to their code. TDD has now become a design process. <br />Expertise in TDD begins to dawn at the point where the developer realizes that TDD is about defining behavior rather than testing. <br />Behavior is about the interactions between components of the system and so the use of mocking is fundamental to advanced TDD. <br />Source: http://behaviour-driven.org/Introduction<br />
  19. 19. Story Time<br />Once upon a time…<br />
  20. 20.
  21. 21. BDD Story Semantics<br />As a <role><br />I want <some feature><br />So that <business value><br />As a speaker<br />I want to be able to select a preferred time of day to present<br />So that I can accommodate my travel plans to attend Code Camp<br />
  22. 22. User Acceptance Tests<br />Scenarios<br />Given <pre-condition><br />And<another pre-condition><br />When <behavior is performed><br />Then <outcome><br />And <another outcome><br />
  23. 23. Scenario 1: Presentation is scheduled according to preferred time of day<br />Given a speaker with an early morning preference<br />And the schedule has an open time slot that matches the preference<br />When the coordinator schedules the session using the speakers preference<br />Then the session is successfully scheduled<br />And the number of open time slots in the schedule is one fewer<br />Scenario 2: Presentation is scheduled into time slot that does not match the speaker’s preference<br />Given a speaker with an early morning preference<br />And a matching time slot is available<br />When the coordinator assigns the session to an afternoon time slot<br />Then the session is not scheduled<br />And the number of open time slots should not change<br />And a warning occurs indicating the conflict<br />Scenario 3: All time slots matching speaker’s preference are taken<br />Given a speaker with a morning preference<br />And a matching time slot is available<br />When the coordinator assigns the session to begin in the morning<br />Then the session is scheduled<br />And the number of open time slots in the schedule is one fewer<br />
  24. 24. Context-Specification Style<br />[Context]<br />When scheduling a session using a speaker’s preference<br />[Specification]<br />should assign to earliest time slot that matches speaker preference<br />[Specification]<br />Should assign earliest available time slot when no others match speakers preference<br />
  25. 25. Tools & Toys<br />StoryQ – a library that uses Domain Specific Language (DSL) of Behavior Driven Development<br />NBehave – similar library. I use for extension methods to assert outcomes<br />AutoHotKey - Automate almost anything by sending keystrokes and mouse clicks. You can write a macro by hand or use the macro recorder.<br />
  26. 26. Resources<br />Email me at: tom@cooley.name<br />http://dannorth.net/introducing-bdd<br />http://behaviour-driven.org/<br />http://storyq.codeplex.com/<br />http://nbehave.codeplex.com/<br />http://www.autohotkey.com/<br />http://blog.jpboodhoo.com/BDDAutoHotKeyScriptUpdateTake1.aspx<br />http://blog.jpboodhoo.com/BDDAutoHotKeyScriptUpdateTake2.aspx<br />

×