Page 1 of 1

Unit Testing with a Registry

Posted: Sat Oct 08, 2005 7:44 pm
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)?

Posted: Sat Oct 08, 2005 10:01 pm
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.