MOCK white box testing

Last night I was introduced to white box testing using nMock and POCMock tools. Mock testing, in a nutshell, provides the required framework to simplify white box testing. Scenarios can be defined that exercise specific code path in your application. Mock'ed classes and methods isolate part of the application code to return predetermined values or throw exceptions. This provide the benefit of:
- exercising hard to reproduce situations (such as specific date or network conditions)
- throw exceptions
- isolate part of your system

Mocking complements unit testing by allowing developers to "mock" part of the application while unit tests are being run: unit tests continue to provide pass/fail indication. I I used to do mock testing by replacing certain parts of the system/application I was building and replace it with a "stub", a fake functional equivalent. MOCK takes this idea and formalizes it, giving developers a structured way to mock part of their system, in the same way unit testing frameworks do (such as nUnit or soon, visual studio team system ;-).

However, it seems that MOCKing is much more immature than unit testing is. From what I gather, there are only 2 frameworks out there: nMOCK (open source) and POCMOCK (commercial app, see http://www.prettyobjects.com/POCMock.aspx?sid=Overview). Furthermore,
MOCKing is much more complex to setup and maintain than unit testing because the code is test case dependant. Each mock must validate parameters, then return values specific to those parameters. MOCKs can even throw exceptions!

Then again, I thought that MOCKs are especially useful in the following scenarios:
- web services: I was burned once designing a system that relied heavily on web services for its business logic. When these WS changed, unit tests could catch the changes but they prevented the rest of the application from passing. Having MOCKs in there would have allowed me to continue testing and even develop by completely de-coupling the web service provider
- database: all my web systems have a database running it. I always endup having some fancy database values for my tests and development. Sometimes I wish I could just have a MOCK that returns predefined values so that I can develop/test in peace.

Posted in |

10 comments:

  1. Anonymous Says:

    There are far more than only two frameworks out there. For starters: jMock (http://www.jmock.org/), EasyMock (http://www.easymock.org), VirtualMock (http://www.virtualmock.org/).

    Mario

  2. Anonymous Says:

    Also you should check out TypeMock http://www.typemock.com this framework can mock any concrete class, without changing the dll's and api's of your code.
    Its also for free

  3. Anonymous Says:

    One good resource for calendar software and many more free software alternatives is Software4YourSuccess.com
    Yes it is my site and I would love for you to drop by for a second. From there you will have free access to several of my products such as The Marketing Toolbar (which is goldmine of information on how to do things quickly and on the cheap, thus saving you time and money).
    Also for webmasters I have created Webmaster Wizards, which will help you with almost every aspect of putting code on your site from things such as legal and privacy disclaimers to popunders. I have so much content and free software there I could fill up this whole blog, so check it out Thanks, Sincerely Rob Rudd

  4. Residual Business Says:

    Hi Farid Mheir, taking a little time today to see what Residual Business will send me to that is interesting. MOCK white box testing looks interesting and is a great read. Will also try Residual Business in my e-travels. Have a super day!

  5. New Home Business Says:

    Hi Farid Mheir, taking a little time today to see what Residual Business will send me to that is interesting. MOCK white box testing looks interesting and is a great read. Will also try Residual Business in my e-travels. Have a super day!

  6. International Business Says:

    Hi Farid Mheir, it’s late in the evening, quiet and peaceful. This is good computer time for me. I thought I would check on Start a Business and see what came up. MOCK white box testing is something that is interesting to many people. I will also spend a little time checking on Start a Business. Getting late, have a good evening.

  7. International Business Says:

    Hi Farid Mheir, I am enjoying some idle time and looking to see what Residual Business will bring up. MOCK white box testing is certainly interesting and informative. Residual Business is a good word to bring into the conversation. Great post. Enjoy your day!

  8. Easy Business Says:

    Hi Farid Mheir, it’s late in the evening, quiet and peaceful. This is good computer time for me. I thought I would check on Easy Business and see what came up. MOCK white box testing is something that is interesting to many people. I will also spend a little time checking on Easy Business. Getting late, have a good evening.

  9. Easy Business Says:

    Hi Farid Mheir, it’s late in the evening, quiet and peaceful. This is good computer time for me. I thought I would check on International Business and see what came up. MOCK white box testing is something that is interesting to many people. I will also spend a little time checking on International Business. Getting late, have a good evening.

  10. International Business Says:

    Hi Farid Mheir, it’s late in the evening, quiet and peaceful. This is good computer time for me. I thought I would check on Start a Business and see what came up. MOCK white box testing is something that is interesting to many people. I will also spend a little time checking on Start a Business. Getting late, have a good evening.