What is the best way to handle iOS and Android in the same code?

I worked on a project that followed design #2. I think it’s a bad idea. The underlying reason is that iOS and Android are two very different platforms. No matter how hard your team tries to make your iOS app and Anroid app appear and behave the same way, there will inevitably be cases where the two apps will be different, and the number of cases where your apps diverge from each other will only grow with time. I ended up having an if-else branch inside a function where the Android branch was on the order of 100 lines long, while the iOS branch was on the order of 10 lines. A bit further down the flow, the Android branch was a few lines long while the iOS branch was several hundred lines. It was a mess. (It also gets worse if you consider just Android. Samsung Android devices will frequently behave differently from most other Android devices. I have a list of Samsung quirks).

You want to be able to abstract some of those platform-specific details away from your test. If you want an example of how a professional, open source project handles the differences between iOS and Android, look at the Appium project :slight_smile:. The Appium server has separate projects for the iOS and Android drivers. The Java library for Appium also provides a separate Android and IOS driver class as well.

3 Likes