Can You Hear Me Now? Tackling Telephony Testing

Preview:

DESCRIPTION

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

Citation preview

Can You Hear Me Now?

Tackling Testing TelephonyBen Klang

bklang@mojolingo.com

Friday, August 10, 12

How Telephony Testing Is Different

Friday, August 10, 12

How Telephony Testing Is Different

•Apps are long-running code

Friday, August 10, 12

How Telephony Testing Is Different

•Apps are long-running code

• Inputs may be more constrained (DTMF)

Friday, August 10, 12

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

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

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

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

How Telephony Testing Is Familiar

Friday, August 10, 12

How Telephony Testing Is Familiar

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

Friday, August 10, 12

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

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

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

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

Philosophy: SRP

Friday, August 10, 12

Philosophy: SRP

•Single Responsibility Principle

Friday, August 10, 12

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

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

SRP Example

Friday, August 10, 12

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

Friday, August 10, 12

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

•Testing requires mocking methods within the same class

Friday, August 10, 12

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

Philosophy: Tell, Don’t Ask

Friday, August 10, 12

Philosophy: Tell, Don’t Ask

•Tell an object to do its work

Friday, August 10, 12

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

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

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

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

Philosophy: Prefer/Share Immutable

Friday, August 10, 12

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

Friday, August 10, 12

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

•Avoid instance vars or other shared state

Friday, August 10, 12

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

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

Prefer/Share Immutable Example

Friday, August 10, 12

Prefer/Share Immutable Example

Friday, August 10, 12

Prefer/Share Immutable Example

Friday, August 10, 12

Prefer/Share Immutable Example

Friday, August 10, 12

Levels of Testing

Friday, August 10, 12

Levels of Testing

Integration

Friday, August 10, 12

Levels of Testing

Integration

Functional

Friday, August 10, 12

Levels of Testing

Integration

Functional

Unit

Friday, August 10, 12

Levels of Testing

Friday, August 10, 12

Levels of Testing

• Integration Testing

Friday, August 10, 12

Levels of Testing

• Integration Testing

•End-to-End

Friday, August 10, 12

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

Friday, August 10, 12

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

•Verify outputs

Friday, August 10, 12

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

•Verify outputs

•Mock as little as possible

Friday, August 10, 12

Integration Testing Tools for Telephony

Friday, August 10, 12

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

Friday, August 10, 12

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

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

Friday, August 10, 12

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

Functional Testing

Friday, August 10, 12

Functional Testing

•Test just one unit in isolation

Friday, August 10, 12

Functional Testing

•Test just one unit in isolation

•Typical unit is a single class

Friday, August 10, 12

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

Unit Testing

Friday, August 10, 12

Unit Testing

•Most common form of testing

Friday, August 10, 12

Unit Testing

•Most common form of testing

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

Friday, August 10, 12

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

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

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

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

Unit Testing Example

Friday, August 10, 12

Unit Testing Example

Friday, August 10, 12

Testing Concurrency

Friday, August 10, 12

Testing Concurrency

•Design with a concurrency model or library

Friday, August 10, 12

Testing Concurrency

•Design with a concurrency model or library

•Celluloid, EventMachine

Friday, August 10, 12

Testing Concurrency

•Design with a concurrency model or library

•Celluloid, EventMachine

•Use State Machines to guarantee sequence

Friday, August 10, 12

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

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

Testing Concurrency

https://github.com/benlangfeld/countdownlatch

Friday, August 10, 12

Testing Concurrency

https://github.com/benlangfeld/countdownlatch

Friday, August 10, 12

http://adhearsion.com/conference/2012

Friday, August 10, 12

Can You Hear Me Now?

Tackling Testing Telephony Ben Klangbklang@mojolingo.com@bklang Github/Twitterspkr8.com/t/12971

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

Friday, August 10, 12

Recommended