Tackling Testing Telephony

263 views

Published on

Tackling Testing Telephony presented by Ben Klang, Mojo Lingo, at Lone Star Ruby Conference 2012

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
263
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tackling Testing Telephony

  1. 1. Can You Hear Me Now?Tackling Testing Telephony Ben Klang bklang@mojolingo.com
  2. 2. How Telephony Testing Is Different
  3. 3. How Telephony Testing Is Different• Apps are long-running code
  4. 4. How Telephony Testing Is Different• Apps are long-running code• Inputs may be more constrained (DTMF)
  5. 5. How Telephony Testing Is Different• Apps are long-running code• Inputs may be more constrained (DTMF)• Or they may be less constrained (IM, Voice)
  6. 6. How Telephony Testing Is Different• Apps are long-running code• Inputs may be more constrained (DTMF)• Or they may be less constrained (IM, Voice)• Lots of things are happening concurrently
  7. 7. How Telephony Testing Is Different• Apps are long-running code• Inputs may be more constrained (DTMF)• Or they may be less constrained (IM, Voice)• Lots of things are happening concurrently • External call interactions (conf, barge)
  8. 8. How Telephony Testing Is Different• Apps are long-running code• Inputs may be more constrained (DTMF)• Or they may be less constrained (IM, Voice)• Lots of things are happening concurrently • External call interactions (conf, barge) • XMPP Events
  9. 9. How Telephony Testing Is Familiar
  10. 10. How Telephony Testing Is Familiar• Same Tooling: rspec, mocha, cucumber, factory_girl, guard, rcov, rake
  11. 11. How Telephony Testing Is Familiar• Same Tooling: rspec, mocha, cucumber, factory_girl, guard, rcov, rake• Still draw lines between M, V and C
  12. 12. How Telephony Testing Is Familiar• Same Tooling: rspec, mocha, cucumber, factory_girl, guard, rcov, rake• Still draw lines between M, V and C• Good class design is important
  13. 13. How Telephony Testing Is Familiar• Same Tooling: rspec, mocha, cucumber, factory_girl, guard, rcov, rake• Still draw lines between M, V and C• Good class design is important
  14. 14. How Telephony Testing Is Familiar• Same Tooling: rspec, mocha, cucumber, factory_girl, guard, rcov, rake• Still draw lines between M, V and C• Good class design is important• It’s Just Ruby
  15. 15. Philosophy: SRP
  16. 16. Philosophy: SRP• Single Responsibility Principle
  17. 17. Philosophy: SRP• Single Responsibility Principle• If you need to use “and” to describe the purpose of a class, you are probably breaking this rule
  18. 18. Philosophy: SRP• Single Responsibility Principle• If you need to use “and” to describe the purpose of a class, you are probably breaking this rule• SRP is key to making classes testable
  19. 19. SRP Example
  20. 20. SRP Example • Class purpose: “To schedule calls and to place them”
  21. 21. SRP Example • Class purpose: “To schedule calls and to place them” • Testing requires mocking methods within the same class
  22. 22. SRP Example • Class purpose: “To schedule calls and to place them” • Testing requires mocking methods within the same class • Non-trivial work to swap calling mechanism
  23. 23. Philosophy: Tell, Don’t Ask
  24. 24. Philosophy: Tell, Don’t Ask• Tell an object to do its work
  25. 25. Philosophy: Tell, Don’t Ask• Tell an object to do its work• Don’t ask for its state then ask it to do something
  26. 26. Philosophy: Tell, Don’t Ask• Tell an object to do its work• Don’t ask for its state then ask it to do something• Works Hand-in-Hand with SRP
  27. 27. Philosophy: Tell, Don’t Ask• Tell an object to do its work• Don’t ask for its state then ask it to do something• Works Hand-in-Hand with SRP
  28. 28. Philosophy: Tell, Don’t Ask• Tell an object to do its work• Don’t ask for its state then ask it to do something• Works Hand-in-Hand with SRP
  29. 29. Philosophy: Prefer/Share Immutable
  30. 30. Philosophy: Prefer/Share Immutable• Methods should only use passed-in data
  31. 31. Philosophy: Prefer/Share Immutable• Methods should only use passed-in data• Avoid instance vars or other shared state
  32. 32. Philosophy: Prefer/Share Immutable• Methods should only use passed-in data• Avoid instance vars or other shared state• Especially helpful with concurrent code
  33. 33. Philosophy: Prefer/Share Immutable• Methods should only use passed-in data• Avoid instance vars or other shared state• Especially helpful with concurrent code• ... but makes testing in general easier
  34. 34. Prefer/Share Immutable Example
  35. 35. Prefer/Share Immutable Example
  36. 36. Prefer/Share Immutable Example
  37. 37. Prefer/Share Immutable Example
  38. 38. Levels of Testing
  39. 39. Levels of Testing Integration
  40. 40. Levels of Testing Integration Functional
  41. 41. Levels of Testing Integration Functional Unit
  42. 42. Levels of Testing
  43. 43. Levels of Testing• Integration Testing
  44. 44. Levels of Testing• Integration Testing • End-to-End
  45. 45. Levels of Testing• Integration Testing • End-to-End • Provide predefined inputs
  46. 46. Levels of Testing• Integration Testing • End-to-End • Provide predefined inputs • Verify outputs
  47. 47. Levels of Testing• Integration Testing • End-to-End • Provide predefined inputs • Verify outputs • Mock as little as possible
  48. 48. Integration Testing Tools for Telephony
  49. 49. Integration Testing Tools for Telephony • sipp: sipp.sourceforge.net
  50. 50. Integration Testing Tools for Telephony • sipp: sipp.sourceforge.net • Loadbot: github.com/mojolingo/ahn-loadbot
  51. 51. Integration Testing Tools for Telephony • sipp: sipp.sourceforge.net • Loadbot: github.com/mojolingo/ahn-loadbot • Cucumber-VoIP: github.com/benlangfeld/cucumber-voip
  52. 52. Functional Testing
  53. 53. Functional Testing• Test just one unit in isolation
  54. 54. Functional Testing• Test just one unit in isolation• Typical unit is a single class
  55. 55. Functional Testing• Test just one unit in isolation• Typical unit is a single class• Test function of class but do not make assertions about internal state
  56. 56. Unit Testing
  57. 57. Unit Testing• Most common form of testing
  58. 58. Unit Testing• Most common form of testing• Test that a given unit (typically: method) behaves the way you expect
  59. 59. Unit Testing• Most common form of testing• Test that a given unit (typically: method) behaves the way you expect• Make sure to test:
  60. 60. Unit Testing• Most common form of testing• Test that a given unit (typically: method) behaves the way you expect• Make sure to test: • Valid inputs
  61. 61. Unit Testing• Most common form of testing• Test that a given unit (typically: method) behaves the way you expect• Make sure to test: • Valid inputs • Invalid inputs
  62. 62. Unit Testing• Most common form of testing• Test that a given unit (typically: method) behaves the way you expect• Make sure to test: • Valid inputs • Invalid inputs • Error Conditions
  63. 63. Unit Testing Example
  64. 64. Unit Testing Example
  65. 65. Testing Concurrency
  66. 66. Testing Concurrency• Design with a concurrency model or library
  67. 67. Testing Concurrency• Design with a concurrency model or library • Celluloid, EventMachine
  68. 68. Testing Concurrency• Design with a concurrency model or library • Celluloid, EventMachine• Use State Machines to guarantee sequence
  69. 69. Testing Concurrency• Design with a concurrency model or library • Celluloid, EventMachine• Use State Machines to guarantee sequence• Mock non-blocking dependent operations with blocking mocks
  70. 70. Testing Concurrency• Design with a concurrency model or library • Celluloid, EventMachine• Use State Machines to guarantee sequence• Mock non-blocking dependent operations with blocking mocks• Always provide a timeout
  71. 71. Testing Concurrency https://github.com/benlangfeld/countdownlatch
  72. 72. Testing Concurrency https://github.com/benlangfeld/countdownlatch
  73. 73. http://adhearsion.com/conference/2012
  74. 74. Can You Hear Me Now?Tackling Testing Telephony Ben Klang bklang@mojolingo.comspkr8.com/t/12971 @bklang Github/TwitterThanks to Ben Langfeld for hisassistance with this presentation@benlangfeld

×