Sunday, December 21, 2008

Unit testing with mocking (JMock)

After a long time I thought to write again in my blog :). Because I got a good experience by writing unit tests with mocking (hoping to share it with you all).
Earlier what I did was try to write Unit testing with using all other 'Active' services. Here what I meant from this 'Active' is, with out using Mock objects I used real EJB and other services. Actually it was a very cruel and bad practice( what I am thinking now :), and it is Integration testing not unit testing :) ). Because if there is a problem with the services which we used, our time will waste on that. ( Remember here I am talking about Unit Testing not about Integration Testing). And if you have to work in a an existing system where you are a new fellow for it, You have to think and understand those other services which will be more time consuming. (Again I am totally agree with you if u say it is good to understand those services as well but first thing is we have to write a correct code.. keep in mind Unit Test).

So a Best thing is Mocking the all other dependent services and test our code as a single Unit. When all the unit tests are passing correctly we know that our single unit is working expectedly.

To mock our dependent services we use Jmock http://www.jmock.org/jmock1.html. It will make our life more easier. These were minor issues but still I think its very good for Unit Testing.

Expecting your comments...

1 comment:

Anonymous said...

EasyMock is much more powerfull than jMock.