Your SlideShare is downloading. ×
0

Pragmatic Test Driven Development

1,671

Published on

Slides from Integrum's

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,671
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Pragmatic Test Driven Development"

  1. 1. Pragmatic Test Driven Development Sunday, January 22, 12
  2. 2. Your Host Clayton Lengel-Zigich clayton@integrumtech.com Certified Scrum Master Certified Scrum Product Owner Certified Scrum Professional @claytonlz Sunday, January 22, 12
  3. 3. Types of Testing Sunday, January 22, 12
  4. 4. Types of Testing Acceptance Integration Unit Sunday, January 22, 12
  5. 5. Types of Testing POÄNG This piece should be 24” These third-party rubber feet should fit Given all of these pieces, I can sit in the chair Sunday, January 22, 12
  6. 6. Types of Testing Acceptance Unit Unit UnitUnit Unit Unit Acceptance Sunday, January 22, 12
  7. 7. Types of Testing Feature Unit Unit Unit Acceptance Feature Unit Unit Unit Acceptance Feature Unit Unit Unit Acceptance Feature Unit Unit Unit Acceptance Feature Unit Unit Unit Acceptance Feature Unit Unit Unit Acceptance Sunday, January 22, 12
  8. 8. Who’s Responsible? Sunday, January 22, 12
  9. 9. Who’s Responsible? QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA QA Sunday, January 22, 12
  10. 10. Who’s Responsible? QA Sunday, January 22, 12
  11. 11. Who Writes Unit Tests? Sunday, January 22, 12
  12. 12. Who Writes Acceptance Tests? DEV CUSTOMER QA Discovery Sunday, January 22, 12
  13. 13. Automated Testing Sunday, January 22, 12
  14. 14. Continuous Integration Continuous integration avoids or detects compatibility problems early ... if you integrate throughout the project in small amounts you will not find your self trying to integrate the system for weeks at the project's end while the deadline slips by. Always work in the context of the latest version of the system. Sunday, January 22, 12
  15. 15. Continuous Integration Build Server SCM SCM Sunday, January 22, 12
  16. 16. Continuous Integration Build Server Compilation Executes Tests Defines Status Sunday, January 22, 12
  17. 17. Continuous Integration 10MINUTE BUILD Sunday, January 22, 12
  18. 18. Test First Programming Sunday, January 22, 12
  19. 19. Test First Programming Sunday, January 22, 12
  20. 20. Test Driven Development Sunday, January 22, 12
  21. 21. Test Driven Development Test Code Test Sunday, January 22, 12
  22. 22. Test Driven Development Failing Passing Refactored Sunday, January 22, 12
  23. 23. Test Driven Development Failing Acceptance Test Failing Unit Test Passing Unit Test Refactor Sunday, January 22, 12
  24. 24. Test Driven Development Code Code Code Code Test Code Code Time CodeTest Time CodeTest CodeTest Test Sunday, January 22, 12
  25. 25. Frameworks and Tools Sunday, January 22, 12
  26. 26. Frameworks And Tools xUnit Sunday, January 22, 12
  27. 27. Frameworks And Tools xUnit Language JUnit Java NUnit .Net TestUnit Ruby QUnit JavaScript PhpUnit PHP Sunday, January 22, 12
  28. 28. Pair Programming Sunday, January 22, 12
  29. 29. Pair Programming Write Test Write Code Sunday, January 22, 12
  30. 30. Tutorial #1 Sunday, January 22, 12
  31. 31. Test Unit Fundamentals test_strike_strike_ball_ball_ball test_full_count vs Sunday, January 22, 12
  32. 32. Test Unit Fundamentals Setup Assertion Assertion Assertion Tear Down Sunday, January 22, 12
  33. 33. Test Unit Fundamentals assert(test, msg = (nomsg = true; nil)) assert_equal(exp, act, msg = nil) assert_no_match(regexp, string, msg=nil) assert_not_equal(exp, act, msg=nil) assert_not_nil(exp, msg=nil) assert_not_same(expected, actual, message="") assert_nothing_raised(*args) assert_nothing_thrown(msg=nil) assert_raise(*args, &b) assert_respond_to(obj, meth, msg = nil) Sunday, January 22, 12
  34. 34. TDD RUles 1.Only write code that makes a test pass 2.Only write enough of a test to make it fail 3.Only write enough code to make a test pass Sunday, January 22, 12
  35. 35. Tutorial #1 In pairs, write a program that can play the game of hangman. 50m Activity Time Sunday, January 22, 12
  36. 36. Mocking & STUBBING Mocks vs. Stubs Indirect Outputs vs. Indirect Inputs Objects vs. Methods Behavior vs. State Sunday, January 22, 12
  37. 37. Mocking Order Warehouse ? ? ? Warehouse Sunday, January 22, 12
  38. 38. Mocking Order Warehouse WarehouseItem order.items.each do |item| warehouse_item = Warehouse.find(item) warehouse_item.stock_reservation.reserve end StockReservation Sunday, January 22, 12
  39. 39. Mocking Order Warehouse Warehouse.reserve(items) Sunday, January 22, 12
  40. 40. Mocking fake_warehouse = mock(Warehouse) assert( fake_warehouse.received("reserve") .with(items), "Expected the warehouse to check its stock" ) Sunday, January 22, 12
  41. 41. STUBBING CUSTOMER “If any items are out-of-stock, the system should prevent the order from completing” Sunday, January 22, 12
  42. 42. STUBBING def test_out_of_stock order = Order.new item1 = Item.new(:sku => "abc") item2 = Item.new(:sku => "def") order.items = [item1, item2] stock_item1 = StockItem.new(:sku => 'zyx') ... end Sunday, January 22, 12
  43. 43. STUBBING def test_invalid_items Warehouse.stub(:reserve) .and_raise(OutOfStockException) assert_raise(OutOfStockException) do order.complete end end Sunday, January 22, 12
  44. 44. Tutorial #2 Sunday, January 22, 12
  45. 45. Tutorial #2 In pairs, write a program that implements Conway’s game of life. 45m Activity Time Sunday, January 22, 12
  46. 46. Game of Life “The universe of the Game of Life is an infinite two- dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:” Sunday, January 22, 12
  47. 47. Game of Life: Rules 1 Any live cell with fewer than two live neighbors dies, as if caused by under-population. 2 Any live cell with two or three live neighbors lives on to the next generation. 3 Any live cell with more than three live neighbors dies, as if by overcrowding. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.4 Sunday, January 22, 12
  48. 48. Closing Sunday, January 22, 12
  49. 49. Test Feedback Listen to your tests Sunday, January 22, 12
  50. 50. Code Coverage DEV MANAGEMENT “If we’re not at 90% code coverage you’re all working on Saturday.” “assert(true)” Sunday, January 22, 12
  51. 51. Continuously Integrate Live and Die by the build Sunday, January 22, 12
  52. 52. Plan to Succeed Write tests before you plan the implementation BDD Failing Unit Test Passing Unit Test Refactor TDD Sunday, January 22, 12
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×