Powered by Twitter Tools.

March 2006
M T W T F S S
« Feb   Apr »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Chris Donnan : Programming - Brooklyn Style

software, trading, family, fun

Mock Frameworks - C#/ .Net and Java

I just wanted to make a few quickie comments on mock frameworks. I have been using Rhino Mocks daily. It is great. In the past I had tried NMock and just found it too clunky.

In short - NMock leaves you with a lot more ’stringy’ stuff to deal with. Rhino is MUCH more in the language. You type normal code. Your refactoring tools work. Your IDE helps you, etc.
The purpose of using a mock framework is basically so you can just work on testing the CUT (class under test). The CUT should usually be the ONLY concrete class in the test. This all works when you are practicing IoC. When you are using IoC - you pass in dependencies from the outside. When you do this - and you are seperating your interfaces from implementation - you can pass mock interfaces to your CUT. Once you do that - the mock can act as a spy.

  1. The mock lets you wriggle into code branches so that you can test pieces of the code that are otherwise difficult to get to.
  2. The mocks make your tests simpler. You do not have to instantiate lots and lots of classes correctly - you just set up interfaces and expectations and you are good.
  3. The mocks make your tests more stable. You do not have to worry about changing test data etc.
  4. The mock can act as a spy and tell you if it is being treated as you expect while it is ‘on the inside’

This used in conjunction with a code coverage tool (like Clover or NCover) helps you to really work your tests to cover your codebase fully.

Carry this over to the Java world - Rhino is much more like EasyMock which I am now writing some tests with. I had formerly used JMock (sort of like NMock in usage) - but I just replaced my jar reference and updated several tests. The tests are immediately more understandable, cleaner and therefore - better.

More another day :) - Maybe I will get around to posting comparison examples.
Chris

Share and Enjoy:
  • del.icio.us
  • digg
  • blinkbits
  • BlinkList
  • blogmarks
  • YahooMyWeb
  • connotea
  • De.lirio.us
  • Fark
  • Furl
  • Reddit
  • description
  • Shadows
  • Smarking
  • Spurl
  • TailRank
  • Wists

Comment on this post below

You must be logged in to post a comment.


You can leave a response, or trackback from your own site.