Across 10 Open Source Apps

In preparation for an upcoming talk at the Seattle Xcoders meetup on February 13th I’m writing a series of short blogs based on some recent spelunking I’ve done. I realized recently, when thinking about Unit Testing, that one of the best ways to learn about best practices is to see how different apps are Unit Tested. I feel I’ve learned more about Unit Testing every time I work on a new application. I’ve been very lucky in my career to work on a number of different applications across a few different companies. It hit me recently that the same kind of opportunity is open to anyone who’s interested.

Some of the top app developers in the world have opened up their work to be examined. While there are over 100 million projects on Github, I chose to focus in on 10 swift projects. Here they are in no particular order:



Open Source Project Links:

https://github.com/brave/brave-ios

https://github.com/wikimedia/wikipedia-ios

https://github.com/mozilla-mobile/firefox-ios

https://github.com/kickstarter/ios-oss

https://github.com/woocommerce/woocommerce-ios

https://github.com/artsy/eidolon

https://github.com/duckduckgo/iOS

https://github.com/wordpress-mobile/WordPress-iOS

https://github.com/danielgindi/Charts

https://github.com/airbnb/MagazineLayout

My main goal when looking at these projects was to see what kind of tests other developers were writing for high quality apps that supported many millions of users a day. I decided to focus on Unit Testing because Unit Tests were the majority of the tests I found when I looked at these projects. Also, I think categories for Mobile Unit Tests are less well defined than they could be. In fact the definition of a Unit Test itself is not entirely agreed upon. The definition I used for Unit Tests when exploring theses apps is as follows:

“Focus On A Unit” is probably the one point above that requires some additional explanation. This is because the argument around “What’s a Unit?” is where much of the argumentation around Unit Testing comes in. Is a single function a Unit? A single object, or a few related objects? For the purposes of my research I was pretty loose with this definition, so YES to all of the above questions as far as my research into these apps was concerned. Plus, I also considered simple view based tests as Unit Tests, hence the Snapshot Tests being included.

In examining these 10 different projects, I wanted to see if I could find certain similarities between the types of Unit Tests that were being written. For various reasons Swift doesn’t have the same testing tools to support it that other languages do. Even in comparison with Objective-C, Swift is lacking basic tools like a widely adopted mocking library. In fact looking at the testing dependencies used by the 10 apps I found very few similarities between apps. Two libraries in particular stood out as being shared by multiple projects: FBSnapshotTestCase and OHHTTPStubs.

In addition to looking at similarities between dependencies in apps, as I mentioned earlier, my main concern was looking at similarities in Unit Tests between apps. Here I did find a significant amount of crossover between apps and the types of Unit Tests that were being written. I’ve listed the types of tests I’ve found below and over the next few weeks I’ll be writing a number of new blogs to explain each type of test in detail, so check back soon!

Part 1: Requirement Tests

Part 2: Black Box Tests