From: sera@... (Francis Hwang) Date: 2003-12-13T05:02:01+09:00 Subject: Re: How to unit test finalizers? Simon Strandgaard wrote in message news:... > On Fri, 12 Dec 2003 23:43:43 +0900, Paul Brannan wrote: > > > On Thu, Dec 11, 2003 at 12:43:52PM +0900, Yukihiro Matsumoto wrote: > >> How about not relying on finalizers, i.e. separate finalizing process > >> into a method, then call the method explicitly in the test? You don't > >> have to test whether finalizers are called. That's my responsibility. > > > > While it is your responsibility to call the finalizers, it is our > > responsibility to make sure that there are no references to the object > > hanging around keeping the object from being finalized. I don't know of > > any good, portable way to unit test that, though. > > Wouldn't it be possible to spawn a child process, where a instance outputs > something when it gets finalized. > Then the parent process could do a assert_equal(count_open, count_close) > > > Is that realistic.. ? I have only played a little with finalizers. One of the things you run into when you try doing things like this is that sometimes resources will persist until after the test methods have all been called. For example, you might have class variables, or variables in a singleton instance, that point to when you want destroyed. So you'll exit your testcases (with either a false positive or a false negative) before the object actually gets GC'd.