mocking 101
DESCRIPTION
Slides from the wellington Dot net user group mocking talk on 2nd April 2008TRANSCRIPT
![Page 1: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/1.jpg)
A brief introduction to test doubles and mocking frameworks
![Page 2: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/2.jpg)
Unit testing goals
Verification Feedback Speed Focus Isolation
![Page 3: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/3.jpg)
Test Doubles
4 types of test doubleDummy – We just pass it round and don’t do
anything with itFake – Working implementations but take
shortcutsStubs – Canned answers to expected callsMocks – Pre programmed with responses
and expectations that certain calls should be made
![Page 4: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/4.jpg)
Why? Feedback cycle needs to be as small as
possible to be useful We need to remove pain points from
being necessaryDatabase callsUIThird party libraries
We can remove reliance on the rest of the code being complete before knowing the current unit works
![Page 5: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/5.jpg)
Mocking frameworks
Provide a repeatable way to set up mocks/stubs/fakes with little code cost.
Test logic can stay within test We can develop as we test and get
immediate results (TDD)
![Page 6: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/6.jpg)
Rhino.Mocks One of the most mature and feature
complete mocking frameworks Uses castle remoting to mock calls
Not able to mock static or sealed calls Fast Record/Replay Syntax Lots of help and code examples
available Open Source
![Page 7: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/7.jpg)
Typemock Isolator
Mature and fully featured Uses IL Generation
Can mock static classes and callsCan chain events
Commercial licence available for full feature set and support
Main commercial mocking framework so features ++
![Page 8: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/8.jpg)
Moq
New Kid on the block .net 3.5 only No record/replay semantics, just
expectations Less code clutter to tests Not feature complete In active development Open source
![Page 9: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/9.jpg)
How?
It’s time to code
![Page 10: Mocking 101](https://reader038.vdocuments.site/reader038/viewer/2022100602/558e1f581a28ab661f8b4674/html5/thumbnails/10.jpg)
Links
Rhino Mocks: http://www.ayende.com/projects/rhino-mocks.aspx
Typemock: http://www.typemock.com/ Moq: http://code.google.com/p/moq Me: http://www.bgeek.net
[email protected]://www.twitter.com/buildmaster