Tdd!

407 views
316 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
407
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tdd!

  1. 1. WTF is TDDA journey to writing awesome code, one test at a time
  2. 2. WTF well be covering● What is testing, Why test, and How testing will make you a better person● What is TDD, why do it, and why its better than writing tests AFTER youve written your code● Go over a code example built out with TDD
  3. 3. Who TF is this guy?● Steven Nunez (@_StevenNunez) ○ Junior Developer at Cyrus Innovation ■ AWESOME PLACE! Premier Dev Shop ● Agile/TDD All day, Eryday ○ Organizer of Unearth Ruby ■ http://www.meetup.com/unearthruby/ ○ Co-Organizer of NYC Rubyist Roundtable ■ http://www.meetup.com/nycruby/
  4. 4. Stuff you need to Fing knowHow to read this:class Order attr_reader :items def initialize @items = Hash.new(0) end def add(item) items[item] += 1 endend
  5. 5. What Is TestingThe Act of isolating parts of your code with aknown state to ensure it works as expected.Setup follows AAA principle:Arrange - Put your code in some stateAct - Cause its state to change (or not)Assert - Verify your getting what you expect
  6. 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 testsWell be covering Unit Tests
  7. 7. Why Test● Lets you know when things break ○ Youd be surprised how code works (or doesnt)● 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 youve done your job is for it to be verified somehow.
  8. 8. Testing basicsWell be using Rspec...http://rspec.info/https://github.com/rspec/rspec-expectations#built-in-matchersCodey Code! ----> http://bit.ly/PUwQLf
  9. 9. What is Test DrivenDevelopment?
  10. 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. 11. How to TDDRed Green Refactor1. Write a test.2. Watch it fail.3. Write code to pass your test.4. Look for ways to make your code more expressive5. GOTO 1
  12. 12. Our taskAvi, in his infinite wisdom has figured that this tech bubble is about to burst and really wants toprepare us for a long healthy life in Fast Food. His newest venture: Avis Ovulating Avians, is aboutique 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 recommendationengine 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 orders ingredients. Well then need tomake recommendations based on those ingredients.Things were buildingA Menu with Menu Items in it.The Items need to have a name, price, calorie count, and ingredientsOrders consist of a menu item, and a quantity.Orders can calculate their totalRecommender can recommend Menu Items based on the ingredients in a menu item.https://github.com/StevenNunez/FlatironDiner
  13. 13. Questions!
  14. 14. Resourceshttps://www.relishapp.com/rspechttp://pragprog.com/book/achbd/the-rspec-bookhttp://www.codeschool.com/courses/testing-with-rspecPractical Object Oriented Design by Sandi Metzhttp://www.poodr.info/
  15. 15. THANKS!

×