Start from Test Zero

Now we have a home for our next set of tests. Before we get into our experiments around life cycles, I’d like to show you a trick. First, whenever I create a new test suite, I start with a special test I call Test Zero. Add the following test to MyClassTests:

LifeCycle/LifeCycleTests/MyClassTests.swift
 func​ ​test_zero​() {
 XCTFail​(​"Tests not yet implemented in MyClassTests"​)
 }

I call it Test Zero because it precedes the first real test we want to write. Go ahead and run tests to make sure it fails. Why? This is a check of our infrastructure. It confirms that our basic test plumbing is correct.

Test Zero helps separate our problems so we can tackle them one at a time. When we create a new test suite, we’re usually thinking about that first test. But before we get lost writing that test, let’s make sure the suite runs. Otherwise, basic infrastructure problems will interrupt our thinking flow.

This is an example of a larger principle: take a small step, get feedback. If you learn nothing else from this book, take that principle home with you.

images/aside-icons/tip.png

Start a new test suite with a test that does nothing but fail. Run your tests to make sure you get the expected failure.

I never write Test Zero by hand. Instead, I use custom XCTest templates to make new test files. You can download the templates I use from my website.[6]