Thursday, December 8, 2016 [Tweets] [Favorites]

How to Do XCTestCase tearDown Wrong (and Right)

Jon Reid (via Natasha Murashev):

In other words, it builds up the entire set of XCTestCase instances before running a single test. […] setUp and tearDown were invented because the entire collection of test cases is created up front. They provide the hooks to manage object life cycle in tests.

This has two important implications:

  1. Anything automatically created as part of the XCTestCase’s initialization will exist too soon.
  2. Anything not released in the tearDown will continue to exist, even while other tests run.

Think of any object that alters global state, and shudder.

Which is too bad because the Swift code isn’t as clean when everything has to be optional, since it isn’t initialized in init.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment