SlideShare a Scribd company logo
1 of 15
Download to read offline
WTF is TDD
A journey to writing awesome code, one test at a time
WTF we'll be covering
● What is testing, Why test, and How testing
  will make you a better person
● What is TDD, why do it, and why it's better
  than writing tests AFTER you've written
  your code
● Go over a code example built out with TDD
Who TF is this guy?
● Steven Nunez (@_StevenNunez)
  ○ Junior Developer at Cyrus Innovation
    ■ AWESOME PLACE! Premier Dev Shop
        ●   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 - Put your code in some state
Act - Cause its state to change (or not)
Assert - Verify your getting what you expect
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


We'll be covering Unit Tests
Why Test
● Lets you know when things break
   ○ You'd be surprised how code works (or doesn't)
● Allows for courageous refactoring
● Gives documentation on how your code is
  SUPPOSED to work. Learn to expect tests.
● It is your duty to deliver working code. The
  only way to ensure you've done your job is
  for it to be verified somehow.
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 task
Avi, in his infinite wisdom has figured that this tech bubble is about to burst and really wants to
prepare us for a long healthy life in Fast Food. His newest venture: Avi's Ovulating Avians, is a
boutique breakfast shop that plans to disrupt the food consumption market in a big way.
He wants to leverage our algorithm wrangling skills to write a food matching meal recommendation
engine to make upselling our products to our unsuspecting patrons easier.
What do we need for version 0.1?
We need a way to capture customer orders, and inspect the order's ingredients. We'll then need to
make recommendations based on those ingredients.

Things we're building
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
Recommender can recommend Menu Items based on the ingredients in a menu item.

https://github.com/StevenNunez/FlatironDiner
Questions!
Resources
https://www.relishapp.com/rspec
http://pragprog.com/book/achbd/the-rspec-book
http://www.codeschool.com/courses/testing-with-rspec

Practical Object Oriented Design by Sandi Metz
http://www.poodr.info/
THANKS!

More Related Content

What's hot

Lab time
Lab timeLab time
Lab timecrebma
 
Masterclass San Francisco: Query workshop
Masterclass San Francisco: Query workshopMasterclass San Francisco: Query workshop
Masterclass San Francisco: Query workshopBrandwatch
 
Working effectively with legacy code chapter1
Working effectively with legacy code chapter1Working effectively with legacy code chapter1
Working effectively with legacy code chapter1Hiroaki NAKADA
 
Putting the D&D in TDD
Putting the D&D in TDDPutting the D&D in TDD
Putting the D&D in TDDGuy Royse
 
DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»
DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»
DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»Dakiry
 
TDD for the rest of us...
TDD for the rest of us...TDD for the rest of us...
TDD for the rest of us...Gil Zilberfeld
 
Apex 10 commandments df14
Apex 10 commandments df14Apex 10 commandments df14
Apex 10 commandments df14James Loghry
 
How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)Rodrigo Ayala
 
Good code, Bad Code
Good code, Bad CodeGood code, Bad Code
Good code, Bad Codejosedasilva
 
Test driven development - why you should test first?
Test driven development - why you should test first?Test driven development - why you should test first?
Test driven development - why you should test first?Abimbola Idowu
 

What's hot (15)

Lab time
Lab timeLab time
Lab time
 
Masterclass San Francisco: Query workshop
Masterclass San Francisco: Query workshopMasterclass San Francisco: Query workshop
Masterclass San Francisco: Query workshop
 
Working effectively with legacy code chapter1
Working effectively with legacy code chapter1Working effectively with legacy code chapter1
Working effectively with legacy code chapter1
 
Putting the D&D in TDD
Putting the D&D in TDDPutting the D&D in TDD
Putting the D&D in TDD
 
Spaceship TDD Style
Spaceship TDD StyleSpaceship TDD Style
Spaceship TDD Style
 
DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»
DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»
DaKiRY_BAQ2016_QADay_Артем Биковець «Agile testing»
 
TDD for the rest of us...
TDD for the rest of us...TDD for the rest of us...
TDD for the rest of us...
 
Apex 10 commandments df14
Apex 10 commandments df14Apex 10 commandments df14
Apex 10 commandments df14
 
How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)
 
Testing economics101
Testing economics101Testing economics101
Testing economics101
 
How to write bad code using C#
How to write bad code using C#How to write bad code using C#
How to write bad code using C#
 
Good code, Bad Code
Good code, Bad CodeGood code, Bad Code
Good code, Bad Code
 
DevOops v2 short
DevOops v2 shortDevOops v2 short
DevOops v2 short
 
Test driven development - why you should test first?
Test driven development - why you should test first?Test driven development - why you should test first?
Test driven development - why you should test first?
 
Lean Startup and Tech
Lean Startup and TechLean Startup and Tech
Lean Startup and Tech
 

Similar to Tdd!

Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and AutomationMahesh Salaria
 
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
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 
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
 
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 with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with LaravelTyler Johnston
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptxAmalEldhose2
 
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...FalafelSoftware
 
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
 
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
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Conceptswesovi
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentbhochhi
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-DrivenIan Truslove
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipCamille Bell
 

Similar to Tdd! (20)

WTF is TDD
WTF is TDDWTF is TDD
WTF is TDD
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
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
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
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
 
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 with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
That worked before
That worked beforeThat worked before
That worked before
 
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
 
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
 
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
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-Driven
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Unit testing
Unit testingUnit testing
Unit testing
 
TDD and Getting Paid
TDD and Getting PaidTDD and Getting Paid
TDD and Getting Paid
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
 

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, Why test, and How testing will make you a better person ● What is TDD, why do it, and why it's better than writing tests AFTER you've written your code ● Go over a code example built out with TDD
  • 3. Who TF is this guy? ● Steven Nunez (@_StevenNunez) ○ Junior Developer at Cyrus Innovation ■ AWESOME PLACE! Premier Dev Shop ● 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 - Put your code in some state Act - Cause its state to change (or not) Assert - Verify your getting what you expect
  • 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 We'll be covering Unit Tests
  • 7. Why Test ● Lets you know when things break ○ You'd be surprised how code works (or doesn't) ● Allows for courageous refactoring ● Gives documentation on how your code is SUPPOSED to work. Learn to expect tests. ● It is your duty to deliver working code. The only way to ensure you've done your job is for it to be verified somehow.
  • 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 task Avi, in his infinite wisdom has figured that this tech bubble is about to burst and really wants to prepare us for a long healthy life in Fast Food. His newest venture: Avi's Ovulating Avians, is a boutique breakfast shop that plans to disrupt the food consumption market in a big way. He wants to leverage our algorithm wrangling skills to write a food matching meal recommendation engine to make upselling our products to our unsuspecting patrons easier. What do we need for version 0.1? We need a way to capture customer orders, and inspect the order's ingredients. We'll then need to make recommendations based on those ingredients. Things we're building 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 Recommender can recommend Menu Items based on the ingredients in a menu item. https://github.com/StevenNunez/FlatironDiner