December 2018
Intermediate to advanced
414 pages
10h 19m
English
A test stub is a collaborator that has canned returns so that we can control the indirect input of the SUT.
Considering the example of the fake, we create a Stub that already has two tasks:
class StubTaskStoreWithTwoTasks: TaskStore { private(set) var allTasks = [Task(), Task()] func add(task: Task) { allTasks.append(task) }}
The test is as follows:
func testAddATaskToPreloadedTasks() { let taskManager = TaskManager(store: StubTaskStoreWithTwoTasks()) taskManager.add(task: Task()) XCTAssertEqual(taskManager.count, 3)}
Read now
Unlock full access