1 / 10

Mocking 101

A brief introduction to test doubles and mocking frameworks. Mocking 101. Unit testing goals. Verification Feedback Speed Focus Isolation. Test Doubles. 4 types of test double Dummy – We just pass it round and don’t do anything with it Fake – Working implementations but take shortcuts

nili
Download Presentation

Mocking 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A brief introduction to test doubles and mocking frameworks Mocking 101

  2. Unit testing goals • Verification • Feedback Speed • Focus • Isolation

  3. Test Doubles • 4 types of test double • Dummy – We just pass it round and don’t do anything with it • Fake – Working implementations but take shortcuts • Stubs – Canned answers to expected calls • Mocks – Pre programmed with responses and expectations that certain calls should be made

  4. Why? • Feedback cycle needs to be as small as possible to be useful • We need to remove pain points from being necessary • Database calls • UI • Third party libraries • We can remove reliance on the rest of the code being complete before knowing the current unit works

  5. 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)

  6. 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

  7. Typemock Isolator • Mature and fully featured • Uses IL Generation • Can mock static classes and calls • Can chain events • Commercial licence available for full feature set and support • Main commercial mocking framework so features ++

  8. 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

  9. How? • It’s time to code

  10. 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.netowen@bgeek.nethttp://www.twitter.com/buildmaster

More Related