Unit Testing with a Registry

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Unit Testing with a Registry

Post by Ambush Commander »

Should the Registry (the well-known object that other objects can use to find other objects) be treated in unit testing as a Mock Object that returns more Mock Objects (and thus have its own parameter)?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

It depends exactly what you're doing.

First off, there are interaction based tests and state based tests.

If you're using mocks you'd be doing the former, ie TDD-ing. If your also testing some other class which uses the Registry, then yes: mock the Registry and set return references for whichever objects you would expect to be returned in the context.

For a state based test, or if you're testing the Registry itself have a look at the link below. The phppatterns.com site is down but you can still find the article in the google cache (I had to put a line break in the link to stop this page pushing out too far to the right).

Marcus Baker's Registry article.
Post Reply