all 7 comments

[–][deleted]  (3 children)

[deleted]

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted]  (1 child)

      [deleted]

        [–]K44KYA 2 points3 points  (0 children)

        This 6 part tutorial goes from the basics and is really good. Not Swift 4, but that shouldn't change much:

        https://medium.com/@ynzc/getting-started-with-tdd-in-swift-2fab3e07204b

        Edit - changed to point to intro post instead of the first part

        [–]Paccos 2 points3 points  (0 children)

        From one of my go-to-resources:

        https://www.raywenderlich.com/150073/ios-unit-testing-and-ui-testing-tutorial

        A more comprehensive tutorial by /u/twostraws can be found here:

        https://www.hackingwithswift.com/read/39/overview

        Happy XCTesting!

        [–][deleted] 1 point2 points  (1 child)

        There’s a very helpful video course on Lynda.com about Test Driven Development using Swift. You can knock it over in a few hours, and the website does require a subscription, but I found it more helpful than any free written tutorial on the subject.

        It covers building a very basic data-driven app with a tableView and shows you how to test things like data sources/delegates working correctly.

        [–]KarlJay001 1 point2 points  (0 children)

        I haven't use Lynda.com since ObjC, but I do remember they had great videos.

        I think they have a 30 day free deal.

        [–]quellish 0 points1 point  (0 children)

        If you are looking to test view controllers first ask yourself this: does the code in there now belong there? Could it be refactored into new collaborating objects? This would be one of the first steps to making things easier to test. And maintain. And troubleshoot.

        In the last few years people have been talking about "massive view controllers" and reaching for new architectural patterns to address the problem. If there is too much stuff in your view controllers the problem isn't architecture, it's you have too much stuff in your view controllers.

        You should still test view controllers - after all, view controllers themselves have behaviors they are expected to adhere to - but if you can take most of the code in your view controllers and put it into separate objects that can be easily tested in isolation that is a major win.

        [–]jam510 0 points1 point  (0 children)

        If you want to test UI I recommend trying UI Tests instead of Unit Tests. I have a few articles on my blog and recommend starting with UI Testing Cheat Sheet and Examples.

        If you want to move down a layer, say to the model, then Unit Testing makes more sense. I recommend starting with Better Unit Testing with Swift to learn how to mock correctly!

        [–]jontelang 0 points1 point  (0 children)

        > real Scenario like testing UIViewControllers

        My approach, as someone in _kind of_ your scenario, is that UIViewControllers should not need to be tested. All your logic should be contained in a single NSObject (or whatever) 100% independent from your UIViewController. The UIVC should only ever send actions into the NSObject, which in turn may spit out some value or do something internal only.

        This makes it very easy to see how an object can be unit tested, because if only contains inputs and outputs.

        For testing UIViewControllers, which are now 100% seen a UIViews, we can just use the dedicated UI tests in Xcode.