Lost on the subcontinent

Distributed Agile, .NET, ThoughtLife

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567


Navigation

Subscriptions

Post Categories



Tuesday, April 06, 2004 - Posts

Fun NMock bug

i discovered a fun little bug in nmock yesterday. i noticed that i was receiving a strange verify exception that was occurring outside of my tests. the exception reported that the Finalize() method was getting called too many times. incidentally, Finalize() is the class destructor -- it is what the ~Class() method gets turned into by the C# compiler. Finalize() is a virtual method, so it was getting overriden by the mock proxy. when the garbage collector went to dispose of the proxy, a verify exception was thrown because i hadn't set up an expectation for my destructor :). note: this is only a problem if you are generating a mock from a concrete class and setting the mock to strict.

to fix the problem, i have ammended the mock class so that it doesn't override the destructor -- i can't imagine why you would want to mock your class' destructor as it is typically something that you don't call directly. it also feels a little bit disconcerting to override the destructor for a base class which might actually be doing something important.

posted Tuesday, April 06, 2004 8:30 PM by exortech




Powered by Dot Net Junkies, by Telligent Systems