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 ...

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.