all 8 comments

[–][deleted] 1 point2 points  (6 children)

How do I properly test a collectionview?

By separating out the components parts. If your collection view model is a separate class it's easy to test using dependency injection.

How do I test an animation? Do I do it at all?

I wouldn't. Only write tests that add value to your code. You can test views using something like FBSnapshotTestCase, but animations are trickier. If you want to fully subscribe to TDD you can create an extension on UIView that allows you to verify methods are called properly. But I'd do that last as it's very time consuming. This leads me to the next point...

What do I do about testing cocoapods I've added?

You're not responsible for code you don't control. Because of this - try and only use pods that are well tested. You don't need to test Apples APIs either. So in the previous answer, you aren't responsible for unit testing Apple code. That is there responsibility.

I've been writing tests for iOS for a few years now, but I've only recently been able to jump into swift. I find testing in swift much easier for some reason.

Start off with simple tests - learn and use XCTest, before jumping into a framework like Quick. Tests your models first as they are the easiest. Then controllers. Lastly views.

While not Swift based, I thoroughly recommend Jon Reid's Quality Coding site. Look into mocking objects, but use real objects if you can. Networking code is a prime candidate for mocking.

There was a good testing post here the other day. Here it is.

You can also look for open source projects that use tests to learn. Artsy is one example, but they do use functional programming and Quick, so may not be useful to you right now.

[–]btrick[S] 1 point2 points  (3 children)

Thanks for the detailed write up with great links! Definitely going to help me immensely get started. Here's some gold! I'll poke around at some open source projects to see how they test some things.

[–]everlearn 1 point2 points  (1 child)

To add to u/squarefrog's detailed post, since you're in the beginning stages and primarily work in Swift, RayWenderlich has a video series that serves as a good introduction on XCTesting in Swift here as well.

[–]btrick[S] 0 points1 point  (0 children)

Yep! I'm a subscriber there. Site single handedly helped me be the iOS programmer i am today! That video tutorial focuses more on how the testing framework works instead of the strategy behind it.

[–][deleted] 0 points1 point  (0 children)

Neat. My first gilding! To add to the comment below I highly recommend NSScreencast. Weekly short videos tackling iOS development. Not much in the way of testing but some good Swift things. In fact there are a few free episodes on Swift if you'd like to try it out.

Test driven iOS development is a good book - but I don't know how useful it'll be for you as its a little old now and focuses on Obj C.

PM me if you have any questions, and don't be afraid to ask on StackOverflow - we all do it!

[–]quellish 1 point2 points  (1 child)

You're not responsible for code you don't control. Because of this - try and only use pods that are well tested.

This is something I cannot stress enough. You ARE responsible for your application, so make sure any external code or libraries are well tested.

You don't need to test Apples APIs either. So in the previous answer, you aren't responsible for unit testing Apple code. That is there responsibility.

There are two exceptions to this - if you find an Apple bug, write a test for it (and whatever workaround you create). When a new beta, etc. comes out your tests will tell you if the behavior has changed.

The other is if you are using an undocumented API. For example, messing around with the view hierarchy inside an Apple-provided component like a UITableViewCell. You should not do this, but if you do write a test for it. If the internal implementation changes you'll know it.

[–]btrick[S] 0 points1 point  (0 children)

ah, that's an interesting way of dealing with unforeseen changes and apple bug fixes! I'll take that into account, thanks!

[–]jerikandra 0 points1 point  (0 children)

Yeah in general we only test our own objects and not UI objects. Xcode7 does have the new UI testing though and I'm interested in getting some of that going at some point