Setting up and tearing down
We have already seen the setUpWithError()
and tearDownWithError()
instance methods earlier in this chapter. The code in the setUpWithError()
instance method is run before each test invocation. In our example, we used setUpWithError()
to initialize the Blogger
that we wanted to test. As it was run before each test invocation, each test used its own instance of Blogger
. The changes we made to this particular instance in one test didn't affect the other test. The tests are executed independently of each other.
The tearDownWithError()
instance method is run after each test invocation. Use tearDownWithError()
to perform the necessary cleanup. In the example, we set the blogger
to nil
in the tearDownWithError()
method.
In addition to the instance methods, there are also the setUp()
and tearDown()
class methods. These are run before and after all the tests of a test case, respectively.