Top Banner
Can You Hear Me Now? Tackling Testing Telephony Ben Klang [email protected]
74

Tackling Testing Telephony

Dec 18, 2014

Download

Technology

Mojo Lingo

Tackling Testing Telephony presented by Ben Klang, Mojo Lingo, at Lone Star Ruby Conference 2012
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tackling Testing Telephony

Can You Hear Me Now?

Tackling Testing TelephonyBen Klang

[email protected]

Page 2: Tackling Testing Telephony

How Telephony Testing Is Different

Page 3: Tackling Testing Telephony

How Telephony Testing Is Different

•Apps are long-running code

Page 4: Tackling Testing Telephony

How Telephony Testing Is Different

•Apps are long-running code

• Inputs may be more constrained (DTMF)

Page 5: Tackling Testing Telephony

How Telephony Testing Is Different

•Apps are long-running code

• Inputs may be more constrained (DTMF)

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

Page 6: Tackling Testing Telephony

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

Page 7: Tackling Testing Telephony

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)

Page 8: Tackling Testing Telephony

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

Page 9: Tackling Testing Telephony

How Telephony Testing Is Familiar

Page 10: Tackling Testing Telephony

How Telephony Testing Is Familiar

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

Page 11: Tackling Testing Telephony

How Telephony Testing Is Familiar

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

•Still draw lines between M, V and C

Page 12: Tackling Testing Telephony

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

Page 13: Tackling Testing Telephony

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

Page 14: Tackling Testing Telephony

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

Page 15: Tackling Testing Telephony

Philosophy: SRP

Page 16: Tackling Testing Telephony

Philosophy: SRP

•Single Responsibility Principle

Page 17: Tackling Testing Telephony

Philosophy: SRP

•Single Responsibility Principle

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

Page 18: Tackling Testing Telephony

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

Page 19: Tackling Testing Telephony

SRP Example

Page 20: Tackling Testing Telephony

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

Page 21: Tackling Testing Telephony

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

•Testing requires mocking methods within the same class

Page 22: Tackling Testing Telephony

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

Page 23: Tackling Testing Telephony

Philosophy: Tell, Don’t Ask

Page 24: Tackling Testing Telephony

Philosophy: Tell, Don’t Ask

•Tell an object to do its work

Page 25: Tackling Testing Telephony

Philosophy: Tell, Don’t Ask

•Tell an object to do its work

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

Page 26: Tackling Testing Telephony

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

Page 27: Tackling Testing Telephony

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

Page 28: Tackling Testing Telephony

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

Page 29: Tackling Testing Telephony

Philosophy: Prefer/Share Immutable

Page 30: Tackling Testing Telephony

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

Page 31: Tackling Testing Telephony

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

•Avoid instance vars or other shared state

Page 32: Tackling Testing Telephony

Philosophy: Prefer/Share Immutable

•Methods should only use passed-in data

•Avoid instance vars or other shared state

•Especially helpful with concurrent code

Page 33: Tackling Testing Telephony

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

Page 34: Tackling Testing Telephony

Prefer/Share Immutable Example

Page 35: Tackling Testing Telephony

Prefer/Share Immutable Example

Page 36: Tackling Testing Telephony

Prefer/Share Immutable Example

Page 37: Tackling Testing Telephony

Prefer/Share Immutable Example

Page 38: Tackling Testing Telephony

Levels of Testing

Page 39: Tackling Testing Telephony

Levels of Testing

Integration

Page 40: Tackling Testing Telephony

Levels of Testing

Integration

Functional

Page 41: Tackling Testing Telephony

Levels of Testing

Integration

Functional

Unit

Page 42: Tackling Testing Telephony

Levels of Testing

Page 43: Tackling Testing Telephony

Levels of Testing

• Integration Testing

Page 44: Tackling Testing Telephony

Levels of Testing

• Integration Testing

•End-to-End

Page 45: Tackling Testing Telephony

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

Page 46: Tackling Testing Telephony

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

•Verify outputs

Page 47: Tackling Testing Telephony

Levels of Testing

• Integration Testing

•End-to-End

•Provide predefined inputs

•Verify outputs

•Mock as little as possible

Page 48: Tackling Testing Telephony

Integration Testing Tools for Telephony

Page 49: Tackling Testing Telephony

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

Page 50: Tackling Testing Telephony

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

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

Page 51: Tackling Testing Telephony

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

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

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

Page 52: Tackling Testing Telephony

Functional Testing

Page 53: Tackling Testing Telephony

Functional Testing

•Test just one unit in isolation

Page 54: Tackling Testing Telephony

Functional Testing

•Test just one unit in isolation

•Typical unit is a single class

Page 55: Tackling Testing Telephony

Functional Testing

•Test just one unit in isolation

•Typical unit is a single class

•Test function of classbut do not makeassertions about internal state

Page 56: Tackling Testing Telephony

Unit Testing

Page 57: Tackling Testing Telephony

Unit Testing

•Most common form of testing

Page 58: Tackling Testing Telephony

Unit Testing

•Most common form of testing

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

Page 59: Tackling Testing Telephony

Unit Testing

•Most common form of testing

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

•Make sure to test:

Page 60: Tackling Testing Telephony

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

Page 61: Tackling Testing Telephony

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

Page 62: Tackling Testing Telephony

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

Page 63: Tackling Testing Telephony

Unit Testing Example

Page 64: Tackling Testing Telephony

Unit Testing Example

Page 65: Tackling Testing Telephony

Testing Concurrency

Page 66: Tackling Testing Telephony

Testing Concurrency

•Design with a concurrency model or library

Page 67: Tackling Testing Telephony

Testing Concurrency

•Design with a concurrency model or library

•Celluloid, EventMachine

Page 68: Tackling Testing Telephony

Testing Concurrency

•Design with a concurrency model or library

•Celluloid, EventMachine

•Use State Machines to guarantee sequence

Page 69: Tackling Testing Telephony

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

Page 70: Tackling Testing Telephony

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

Page 71: Tackling Testing Telephony

Testing Concurrency

https://github.com/benlangfeld/countdownlatch

Page 72: Tackling Testing Telephony

Testing Concurrency

https://github.com/benlangfeld/countdownlatch

Page 74: Tackling Testing Telephony

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