SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
WTF is TDD
A journey to writing awesome code, one test at a time
WTF we'll be covering
● What is testing and why you are hurting the
  world by not doing it
● What is TDD, why do it, and why it's better
  than writing tests AFTER you've written
  your code
● See code that was developed using TDD
● Extending this code
Who TF is this guy?
● Steven Nunez (@_StevenNunez)
  ○ Junior Developer at Cyrus Innovation
    ■ AWESOME PLACE!
        ●   Agile/TDD All day, E'ryday
  ○ Organizer of Unearth Ruby
    ■ http://www.meetup.com/unearthruby/
  ○ Co-Organizer of NYC Rubyist Roundtable
    ■ http://www.meetup.com/nycruby/
Stuff you need to F'ing know
How to read this:
class Order
 attr_reader :items

 def initialize
  @items = Hash.new(0)
 end

 def add(item)
  items[item] += 1
 end
end
What Is Testing
The Act of isolating parts of your code with a
known state to ensure it works as expected.

Setup follows AAA principle:

Arrange
Act
Assert
Types of testing
● End to end tests/ Acceptance tests
  ○ Here there be Cucumbers. Capybara, Webrat
  ○ Used to ensure system works as a whole
● Unit Tests
  ○   Rspec, Test::Unit, Minitest
  ○   View tests
  ○   Controller tests
  ○   Model tests
Why Test
● Lets you know when things broke
  ○ You'd be surprised how code works
● Allows for courageous refactoring
● Gives documentation on how your code is
  SUPPOSED to work
● It is your duty to deliver working code.
Testing basics
We'll be using Rspec...
http://rspec.info/
https://github.com/rspec/rspec-
expectations#built-in-matchers

Codey Code! ----> http://bit.ly/PUwQLf
What is Test Driven
Development?
Why do TDD?
● Forces you to think small
             ○ You have a clear objective
● Less thoughts to juggle
             ○ All you know is how you want it to work
● Leads to modular code
             ○ Each part of your code does one job
● Write less code
● Increase documentation
● It makes you happy!
             ○ Red, Green, REFACTOR!
http://edu.mkrecny.com/thoughts/be-nice-to-programmers
How to TDD
Red Green Refactor
1. Write a test.
2. Watch it fail.
3. Write code to pass your test.
4. Look for ways to make your code more
   expressive
5. GOTO 1
Our project
Our client is developing a social network based for his Restaurant customers. He'd want to eventually have people with
similar food interests meet up and discuss how his food changed their lives.
  ●    A few features he wants are:
        ○    The ability to have users discover new foods based on ingredients they love (Bacon!)
        ○    The ability to find users with similar food interests. The system will automatically share their phone
             numbers with each other. (He thinks they'll be ok with this)
What do you need first?
I need a way to capture customer orders based on their menu.


Things we built
A Menu with Menu Items in it.
The Items need to have a name, price, calorie count, and ingredients
Orders consist of a menu item, and a quantity.
Orders can calculate their total
Your task!
Pair up and work on getting the
recommendation engine up.

Noobs, pair up with Wizards.

TDD ONLY!

https://github.com/StevenNunez/FinerDiner
Questions!
Task
Menu#recommendations(:bacon)
# => [:bacon_cheeseburger, :blt, :bacone ]

Socializer#socialize!
# customer_1.hook_up(customer_2)
Resources
https://www.relishapp.com/rspec
http://pragprog.com/book/achbd/the-rspec-
book
Practical Object Oriented Design by Sandy
Mentz
http://www.poodr.info/
THANKS!

Weitere ähnliche Inhalte

Ähnlich wie WTF is TDD

Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 
Coderetreat @ CodersTUG
Coderetreat @ CodersTUGCoderetreat @ CodersTUG
Coderetreat @ CodersTUGMatteo Baglini
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and AutomationMahesh Salaria
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
TDD BDD PHP - Sviluppo guidato dai test in PHP con phpspec
TDD BDD PHP - Sviluppo guidato dai test in PHP con phpspecTDD BDD PHP - Sviluppo guidato dai test in PHP con phpspec
TDD BDD PHP - Sviluppo guidato dai test in PHP con phpspecPatrick Luca Fazzi
 
Global Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventGlobal Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventLemi Orhan Ergin
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1Blue Elephant Consulting
 
You cant be agile if your code sucks
You cant be agile if your code sucksYou cant be agile if your code sucks
You cant be agile if your code sucksPeter Gfader
 
TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeNacho Cougil
 
Behavior Driven Education: A Story of Learning ROR
Behavior Driven Education: A Story of Learning RORBehavior Driven Education: A Story of Learning ROR
Behavior Driven Education: A Story of Learning RORSmartLogic
 
Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): RevistedMike Harris
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipCamille Bell
 

Ähnlich wie WTF is TDD (20)

Tdd!
Tdd!Tdd!
Tdd!
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
That worked before
That worked beforeThat worked before
That worked before
 
Coderetreat @ CodersTUG
Coderetreat @ CodersTUGCoderetreat @ CodersTUG
Coderetreat @ CodersTUG
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
What is xp
What is xpWhat is xp
What is xp
 
TDD BDD PHP - Sviluppo guidato dai test in PHP con phpspec
TDD BDD PHP - Sviluppo guidato dai test in PHP con phpspecTDD BDD PHP - Sviluppo guidato dai test in PHP con phpspec
TDD BDD PHP - Sviluppo guidato dai test in PHP con phpspec
 
Global Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventGlobal Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul Event
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
You cant be agile if your code sucks
You cant be agile if your code sucksYou cant be agile if your code sucks
You cant be agile if your code sucks
 
Code Retreat
Code RetreatCode Retreat
Code Retreat
 
TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - Opensouthcode
 
Behavior Driven Education: A Story of Learning ROR
Behavior Driven Education: A Story of Learning RORBehavior Driven Education: A Story of Learning ROR
Behavior Driven Education: A Story of Learning ROR
 
Git Makes Me Angry Inside
Git Makes Me Angry InsideGit Makes Me Angry Inside
Git Makes Me Angry Inside
 
Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): Revisted
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
 

WTF is TDD

  • 1. WTF is TDD A journey to writing awesome code, one test at a time
  • 2. WTF we'll be covering ● What is testing and why you are hurting the world by not doing it ● What is TDD, why do it, and why it's better than writing tests AFTER you've written your code ● See code that was developed using TDD ● Extending this code
  • 3. Who TF is this guy? ● Steven Nunez (@_StevenNunez) ○ Junior Developer at Cyrus Innovation ■ AWESOME PLACE! ● Agile/TDD All day, E'ryday ○ Organizer of Unearth Ruby ■ http://www.meetup.com/unearthruby/ ○ Co-Organizer of NYC Rubyist Roundtable ■ http://www.meetup.com/nycruby/
  • 4. Stuff you need to F'ing know How to read this: class Order attr_reader :items def initialize @items = Hash.new(0) end def add(item) items[item] += 1 end end
  • 5. What Is Testing The Act of isolating parts of your code with a known state to ensure it works as expected. Setup follows AAA principle: Arrange Act Assert
  • 6. Types of testing ● End to end tests/ Acceptance tests ○ Here there be Cucumbers. Capybara, Webrat ○ Used to ensure system works as a whole ● Unit Tests ○ Rspec, Test::Unit, Minitest ○ View tests ○ Controller tests ○ Model tests
  • 7. Why Test ● Lets you know when things broke ○ You'd be surprised how code works ● Allows for courageous refactoring ● Gives documentation on how your code is SUPPOSED to work ● It is your duty to deliver working code.
  • 8. Testing basics We'll be using Rspec... http://rspec.info/ https://github.com/rspec/rspec- expectations#built-in-matchers Codey Code! ----> http://bit.ly/PUwQLf
  • 9. What is Test Driven Development?
  • 10. Why do TDD? ● Forces you to think small ○ You have a clear objective ● Less thoughts to juggle ○ All you know is how you want it to work ● Leads to modular code ○ Each part of your code does one job ● Write less code ● Increase documentation ● It makes you happy! ○ Red, Green, REFACTOR! http://edu.mkrecny.com/thoughts/be-nice-to-programmers
  • 11. How to TDD Red Green Refactor 1. Write a test. 2. Watch it fail. 3. Write code to pass your test. 4. Look for ways to make your code more expressive 5. GOTO 1
  • 12. Our project Our client is developing a social network based for his Restaurant customers. He'd want to eventually have people with similar food interests meet up and discuss how his food changed their lives. ● A few features he wants are: ○ The ability to have users discover new foods based on ingredients they love (Bacon!) ○ The ability to find users with similar food interests. The system will automatically share their phone numbers with each other. (He thinks they'll be ok with this) What do you need first? I need a way to capture customer orders based on their menu. Things we built A Menu with Menu Items in it. The Items need to have a name, price, calorie count, and ingredients Orders consist of a menu item, and a quantity. Orders can calculate their total
  • 13. Your task! Pair up and work on getting the recommendation engine up. Noobs, pair up with Wizards. TDD ONLY! https://github.com/StevenNunez/FinerDiner
  • 15. Task Menu#recommendations(:bacon) # => [:bacon_cheeseburger, :blt, :bacone ] Socializer#socialize! # customer_1.hook_up(customer_2)