The Importance of Setup and Teardown

When we run xUnit tests, each scenario is isolated from other scenarios, and the tests are typically stateless. However, sometimes different test scenarios have the same setup sequence. Likewise, sometimes test scenarios create artifacts that need to be cleaned up after every run or use unmanaged resources that have to be disposed of correctly. These aspects entail the setup and teardown logic.

The following playground demonstrates examples of the setup and teardown logic in xUnit:

Get hands-on with 1400+ tech skills courses.