Chapter 22Fixture Teardown Patterns

Patterns in This Chapter

Teardown Strategy

      Garbage-Collected Teardown 500

      Automated Teardown 503

Code Organization

      In-line Teardown 509

      Implicit Teardown 516

Garbage-Collected Teardown

How do we tear down the Test Fixture?

We let the garbage collection mechanism provided by the programming language clean up after our test.


A large part of making tests repeatable and robust is ensuring that the test fixture is torn down after each test and a new one created for the next test run. This strategy is known as a Fresh Fixture (page 311). In languages that provide garbage collection, much of ...

Get xUnit Test Patterns: Refactoring Test Code now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.