O'Reilly logo

Test-Driven iOS Development with Swift 4 - Third Edition by Dr. Dominik Hauser

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding and checking items

The item manager should be able to add items to the list. Therefore, it should provide a method that takes an item. Later, we can call this method from the ViewController that will provide a UI to add items. Add the following code to ItemManagerTests:

func test_AddItem_IncreasesToDoCountToOne() { 
  sut.add(ToDoItem(title: "")) 
} 

Here, we assume that ItemManager has an add(_:) method. You can see how TDD helps us think about the class/struct interface before a feature is implemented.

The ItemManager class does not have an add(_:) method and the test does not compile. Let's add the simplest implementation of add(_:):

func add(_ item: ToDoItem) { 
} 

Run the tests to make sure they all pass. Now, we need to assert that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required