Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mocking 101

2,519 views

Published on

Slides from the wellington Dot net user group mocking talk on 2nd April 2008

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Mocking 101

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

×