23
testing with mock objects

Testing with Mock Objects

Embed Size (px)

DESCRIPTION

A presentation on the value of mock objects when using TDD.

Citation preview

Page 1: Testing with Mock Objects

testing with mock objects

Page 2: Testing with Mock Objects

when i say testing…

== developer / unit tests

== integration tests (sometimes)

!= functional / acceptance tests

Page 3: Testing with Mock Objects

when i say mock…

test stub

mock object

dummy object

fake object

Page 4: Testing with Mock Objects

mock vs. stub interaction vs. state

the difference between mocks and stubs

usually the same library provides both

interaction = mock

state = stub

Page 5: Testing with Mock Objects

why?

Page 6: Testing with Mock Objects

testing is easy in isolation

Class Under Test

Test Class

Page 7: Testing with Mock Objects

testing is harder with dependencies …

Class Under Test

Test Class

Page 8: Testing with Mock Objects

… so remove the dependencies (for developer testing)

Class Under Test

Test Class

mock

mock

mockm

ock

Page 9: Testing with Mock Objects

for me…

lots of time in the airport

lots of time in the airplane

lots of time on the train

not enough family time

not enough snowboarding

Page 10: Testing with Mock Objects

scenarios to think about

fee per transaction

distributed development

parallel development

plug-ins / providers

automated test duration

Page 11: Testing with Mock Objects

scenarios to think about

third-party tools or services

non-deterministic outcomes

external systems

the mainframe crew

defer infrastructure choices

Page 12: Testing with Mock Objects

demo

Page 13: Testing with Mock Objects

thoughts

Page 14: Testing with Mock Objects

… on architecture and design

similar to the benefits of tdd

writing to interfaces = code empathy

easier to test = good design

highly cohesive / loosely coupled

Page 15: Testing with Mock Objects

… on implementation

good libraries exist

roll your own only for extreme cases

for .Net…

NMock, NMock2, Rhino Mocks, DotNetMock

Page 16: Testing with Mock Objects

… on automated builds

developer tests: use mocks (if necessary)

acceptance tests: don’t use mocks

Page 17: Testing with Mock Objects

… on a few useful patterns

code to interfaces

thin proxies

self-shunt

dependency injection

providers

Page 18: Testing with Mock Objects

learn more

Page 21: Testing with Mock Objects

http://www.nmock.org

Page 22: Testing with Mock Objects

http://www.mockobjects.com