How do I unit test a finalizer?

前端 未结 4 1506
不思量自难忘°
不思量自难忘° 2021-02-05 07:25

I have the following class which is a decorator for an IDisposable object (I have omitted the stuff it adds) which itself implements IDisposable using

4条回答
  •  无人及你
    2021-02-05 08:02

    When writing unit tests, you should always try to test outside visible behavior, not implementation details. One could argue that supressing finalization is indeed outside visible behavior, but on the other hand, there's probably no way you can (nor should you) mock out the garabage collector.

    What you try to make sure in your case, is that a "best-practice" or a coding practice is followed. It should be enforced via a tool that is made for this purpose, such as FxCop.

提交回复
热议问题