kodeco.com Forums

Unit Testing Tutorial: Mocking Objects

In this tutorial you’ll learn how to write your own mocks, fakes and stubs to test a simple app that helps you remember your friends birthdays.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1752-unit-testing-tutorial-mocking-objects

couldn’t get XCTAssert(storeCoordinator.removePersistentStore(store, error: &error),
“couldn’t remove persistent store: (error)”) in teardown()
to work in swift 2.0 can anyone help? after upgrading

You’ve got to update it to a try/catch block.

    do {
        try storeCoordinator.removePersistentStore(store)
    } catch {
        print("couldn't remove persistent store: \(error)")

so many bugs in starter code :frowning: can’t compile

even with old xcode 7.3

/Downloads/Birthdays_Starter-2/Birthdays/PeopleListDataProvider.swift:182:15: Objective-C method ‘controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:’ provided by method ‘controller(:didChangeObject:atIndexPath:forChangeType:newIndexPath:)’ conflicts with optional requirement method 'controller(:didChangeObject:atIndexPath:forChangeType:newIndexPath:)’ in protocol ‘NSFetchedResultsControllerDelegate’

Copy the code in that method, then reimplement the didChangeObject method, and paste the code in. I just completed the tutorial. There should be no more major bugs that aren’t already listed.

I’m getting the same error after updating the swift version. Can you elaborate fibonnacired on how to resolve the error. I do not see the didChangeObject method implemented anywhere and seems to only be used as a parameter in the controller method. I’m very new to swift so might be missing something completely obvious. Thanks.

I see now. Rewrite “public func controller”, tab to autocomplete, then paste in the code. Replaces “didChangeObject anObject: NSManagedObject” with “didChangeObject anObject: AnyObject” Thanks!

Can we get a new sample project for iOS 10 with Swift 3.0 please?

How do you test the behaviour of a method that uses internal private access method in its logic ? How to write mock to private method ? Does it make sense ?

This tutorial is more than six months old, so questions regarding it are no longer supported. We will update it as soon as possible. Thank you! :]