Mock objects not compile aware

28 Feb

When I use mock objects in this case NMock, I would really like to have compile time check that passing the paramters to the expectation as strings

Example

Expect.Once.On(dbHelper).Method("GetRequestsForUser")
.With(userID).Will(Return.Value(requests));

In case in point above I am expecting that when i call the helper in that a method called GetRequestsForUser with userId
will return something

The problem is the mock framework is quite dumb until invoked.

When i want to refactor by adding a new parameter to the method GetRequestsForUser, the compiler has no clue that i have to change the test above.

Does anyone know the intent behind choosing such a design for the mock framework. Is there something more smart out there.

Update: Found out from one of my friends about Rhino mock. A typed mock framework. I haven’t used it yet, but plan to try it out soon.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.