The setUp() and tearDown() methods

We have already seen the setUp() and tearDown() instance methods earlier in this chapter. The code in the setUp() instance method is run before each test invocation. In our example, we used setUp() to initialize ViewController that we wanted to test. As it was run before each test invocation, each test used its own instance of ViewController. The changes we made to this particular instance in one test didn't affect the other test. The tests executed independently of each other.

The tearDown() instance method is run after each test invocation. Use tearDown() to perform the necessary cleanup.

In addition to the instance methods, there are also the setUp() and tearDown() class methods. These are run before ...

Get Test-Driven iOS Development with Swift 4 - Third Edition now with O’Reilly online learning.

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