can you hear me now? tackling telephony testing

74
Can You Hear Me Now? Tackling Testing Telephony Ben Klang [email protected] Friday, August 10, 12

Upload: adhearsion-foundation

Post on 15-Jan-2015

375 views

Category:

Technology


1 download

DESCRIPTION

This presentation was given by Ben Klang as part of Lone Star Ruby Conference 6

TRANSCRIPT

Page 1: Can You Hear Me Now? Tackling Telephony Testing

Can You Hear Me Now?

Tackling Testing TelephonyBen Klang

[email protected]

Friday, August 10, 12

Page 2: Can You Hear Me Now? Tackling Telephony Testing

How Telephony Testing Is Different

Friday, August 10, 12

Page 3: Can You Hear Me Now? Tackling Telephony Testing

How Telephony Testing Is Different

•Apps are long-running code

Friday, August 10, 12

Page 4: Can You Hear Me Now? Tackling Telephony Testing

How Telephony Testing Is Different

•Apps are long-running code

• Inputs may be more constrained (DTMF)

Friday, August 10, 12

Page 5: Can You Hear Me Now? Tackling Telephony Testing

How Telephony Testing Is Different

•Apps are long-running code

• Inputs may be more constrained (DTMF)

•Or they may be less constrained (IM, Voice)

Friday, August 10, 12

Page 6: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 7: Can You Hear Me Now? Tackling Telephony Testing

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)

Friday, August 10, 12

Page 8: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 9: Can You Hear Me Now? Tackling Telephony Testing

How Telephony Testing Is Familiar

Friday, August 10, 12

Page 10: Can You Hear Me Now? Tackling Telephony Testing

How Telephony Testing Is Familiar

•Same Tooling: rspec, mocha, cucumber, factory_girl, guard, rcov, rake

Friday, August 10, 12

Page 11: Can You Hear Me Now? Tackling Telephony Testing

How Telephony Testing Is Familiar

•Same Tooling: rspec, mocha, cucumber, factory_girl, guard, rcov, rake

•Still draw lines between M, V and C

Friday, August 10, 12

Page 12: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 13: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 14: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 15: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: SRP

Friday, August 10, 12

Page 16: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: SRP

•Single Responsibility Principle

Friday, August 10, 12

Page 17: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: SRP

•Single Responsibility Principle

• If you need to use “and” to describe the purpose of a class, you are probably breaking this rule

Friday, August 10, 12

Page 18: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 19: Can You Hear Me Now? Tackling Telephony Testing

SRP Example

Friday, August 10, 12

Page 20: Can You Hear Me Now? Tackling Telephony Testing

SRP Example•Class purpose: “To schedule calls and to place them”

Friday, August 10, 12

Page 21: Can You Hear Me Now? Tackling Telephony Testing

SRP Example•Class purpose: “To schedule calls and to place them”

•Testing requires mocking methods within the same class

Friday, August 10, 12

Page 22: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 23: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: Tell, Don’t Ask

Friday, August 10, 12

Page 24: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: Tell, Don’t Ask

•Tell an object to do its work

Friday, August 10, 12

Page 25: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: Tell, Don’t Ask

•Tell an object to do its work

•Don’t ask for its state then ask it to do something

Friday, August 10, 12

Page 26: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 27: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 28: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 29: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: Prefer/Share Immutable

Friday, August 10, 12

Page 30: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

Friday, August 10, 12

Page 31: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

•Avoid instance vars or other shared state

Friday, August 10, 12

Page 32: Can You Hear Me Now? Tackling Telephony Testing

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

•Avoid instance vars or other shared state

•Especially helpful with concurrent code

Friday, August 10, 12

Page 33: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 34: Can You Hear Me Now? Tackling Telephony Testing

Prefer/Share Immutable Example

Friday, August 10, 12

Page 35: Can You Hear Me Now? Tackling Telephony Testing

Prefer/Share Immutable Example

Friday, August 10, 12

Page 36: Can You Hear Me Now? Tackling Telephony Testing

Prefer/Share Immutable Example

Friday, August 10, 12

Page 37: Can You Hear Me Now? Tackling Telephony Testing

Prefer/Share Immutable Example

Friday, August 10, 12

Page 38: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

Friday, August 10, 12

Page 39: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

Integration

Friday, August 10, 12

Page 40: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

Integration

Functional

Friday, August 10, 12

Page 41: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

Integration

Functional

Unit

Friday, August 10, 12

Page 42: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

Friday, August 10, 12

Page 43: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

• Integration Testing

Friday, August 10, 12

Page 44: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

• Integration Testing

•End-to-End

Friday, August 10, 12

Page 45: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

Friday, August 10, 12

Page 46: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

•Verify outputs

Friday, August 10, 12

Page 47: Can You Hear Me Now? Tackling Telephony Testing

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

•Verify outputs

•Mock as little as possible

Friday, August 10, 12

Page 48: Can You Hear Me Now? Tackling Telephony Testing

Integration Testing Tools for Telephony

Friday, August 10, 12

Page 49: Can You Hear Me Now? Tackling Telephony Testing

Integration Testing Tools for Telephony• sipp:sipp.sourceforge.net

Friday, August 10, 12

Page 50: Can You Hear Me Now? Tackling Telephony Testing

Integration Testing Tools for Telephony• sipp:sipp.sourceforge.net

• Loadbot:github.com/mojolingo/ahn-loadbot

Friday, August 10, 12

Page 51: Can You Hear Me Now? Tackling Telephony Testing

Integration Testing Tools for Telephony• sipp:sipp.sourceforge.net

• Loadbot:github.com/mojolingo/ahn-loadbot

• Cucumber-VoIP:github.com/benlangfeld/cucumber-voip

Friday, August 10, 12

Page 52: Can You Hear Me Now? Tackling Telephony Testing

Functional Testing

Friday, August 10, 12

Page 53: Can You Hear Me Now? Tackling Telephony Testing

Functional Testing

•Test just one unit in isolation

Friday, August 10, 12

Page 54: Can You Hear Me Now? Tackling Telephony Testing

Functional Testing

•Test just one unit in isolation

•Typical unit is a single class

Friday, August 10, 12

Page 55: Can You Hear Me Now? Tackling Telephony Testing

Functional Testing

•Test just one unit in isolation

•Typical unit is a single class

•Test function of classbut do not makeassertions about internal state

Friday, August 10, 12

Page 56: Can You Hear Me Now? Tackling Telephony Testing

Unit Testing

Friday, August 10, 12

Page 57: Can You Hear Me Now? Tackling Telephony Testing

Unit Testing

•Most common form of testing

Friday, August 10, 12

Page 58: Can You Hear Me Now? Tackling Telephony Testing

Unit Testing

•Most common form of testing

•Test that a given unit (typically: method) behaves the way you expect

Friday, August 10, 12

Page 59: Can You Hear Me Now? Tackling Telephony Testing

Unit Testing

•Most common form of testing

•Test that a given unit (typically: method) behaves the way you expect

•Make sure to test:

Friday, August 10, 12

Page 60: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 61: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 62: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 63: Can You Hear Me Now? Tackling Telephony Testing

Unit Testing Example

Friday, August 10, 12

Page 64: Can You Hear Me Now? Tackling Telephony Testing

Unit Testing Example

Friday, August 10, 12

Page 65: Can You Hear Me Now? Tackling Telephony Testing

Testing Concurrency

Friday, August 10, 12

Page 66: Can You Hear Me Now? Tackling Telephony Testing

Testing Concurrency

•Design with a concurrency model or library

Friday, August 10, 12

Page 67: Can You Hear Me Now? Tackling Telephony Testing

Testing Concurrency

•Design with a concurrency model or library

•Celluloid, EventMachine

Friday, August 10, 12

Page 68: Can You Hear Me Now? Tackling Telephony Testing

Testing Concurrency

•Design with a concurrency model or library

•Celluloid, EventMachine

•Use State Machines to guarantee sequence

Friday, August 10, 12

Page 69: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 70: Can You Hear Me Now? Tackling Telephony Testing

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

Friday, August 10, 12

Page 71: Can You Hear Me Now? Tackling Telephony Testing

Testing Concurrency

https://github.com/benlangfeld/countdownlatch

Friday, August 10, 12

Page 72: Can You Hear Me Now? Tackling Telephony Testing

Testing Concurrency

https://github.com/benlangfeld/countdownlatch

Friday, August 10, 12

Page 73: Can You Hear Me Now? Tackling Telephony Testing

http://adhearsion.com/conference/2012

Friday, August 10, 12

Page 74: Can You Hear Me Now? Tackling Telephony Testing

Can You Hear Me Now?

Tackling Testing Telephony Ben [email protected]@bklang Github/Twitterspkr8.com/t/12971

Thanks to Ben Langfeld for his assistance with this presentation@benlangfeld

Friday, August 10, 12