Detox vs. Appium: automated UI tests in React Native

Developer’s edition

Jurijs Yuri Bormanis
Reactive Hub
7 min readDec 29, 2018

--

All new mobile environment

Probably just like you I came to React Native from different JavaScript background rather than as a native mobile developer. This is completely new environment with its bits and tricks to learn.

One of the important new fields you have to explore is testing. When it’s more or less clear in unit tests, how do we handle UI tests, end-to-end? There’s iOS, there’s Android. Market with lots of devices to choose from.

Despite its relatively new tech compared to native mobile, it’s still a mobile environment and many things we take and learn from native side.

Here are two frameworks I considered to use to make my life easier as React Native developer.

Appium

Using Selenium WebDriver behind the scenes Appium is a powerful testing framework with the large native mobile community behind it. Released even before React.js this is the number one in the industry.

Start is easy just by installing “appium” and “appium-doctor” packages globally or for your project using npm. Running “appium-doctor” command will tell you what you need to add and install on your system before writing and running the tests and if possible can help you fix the issues. When it’s all sorted, packages installed and jest configuration is in place, you can start Appium server and then run your tests.

I’m not going to detail too much test setup and writing process but this is how basic test looks like (with comments added):

The actual test part is the last few Jest lines that check if there’s text “OK” and “Home Screen” on the screen. As you can see it looks like typical Jest test so there are no problems to write it. Appium documentation page gives you overview of capabilities and examples.

The line to dislike is line `await driver.sleep(4000)`. We need it because tests doesn’t know what the hell is actually happening in the app. Black box. Imagine if would you write some Node code with http call and set timeout before it instead of using promise or callback. Flakiness.

In this basic setup we tell Appium (webdriver) to wait for 4 seconds before start the test since we need to launch the app and go past “LaunchScreen”, but as app becomes more complex, you will need to use it more often — http calls or animations, react-native itself — the bridge between JavaScript and native code will cause a delays.

There are alternatives such as Implicit Wait but it doesn’t change the Black Box model.

Blackbox testing, we have built of our app with no access to internal structure.

What I Like about Appium

  • 7+ years in industry.
  • API capabilities, thumbs up.
  • Easy to find help & support online (also dislike, see below)
  • Various languages supported to write your tests including JavaScript.
  • Usual for JS developer environment for writing tests using Jest.
  • Used for end-to-end tests on MS AppCenter, BrowserStack and AWS Device Farm.
  • Tests with real devices.

What I Dislike about Appium

  • Searching for assistance online gives back results in all different languages, most of it in Java.
  • Black box testing (tests doesn’t know about internal process)
  • Works out of sync with the app. Flaky, even more flaky on react native.
  • testID prop ignored in Android case.
Notice three tabs in Terminal. Appium server logs, metro bundler and tests itself.

Detox

Wix’s Detox works similar way as Appium but important difference here is a Gray box testing. One of the reason why Detox was born is to solve “flakiness” problem — it will wait until action in app is finished and will continue only when app is idle. This is possible because of other framework called EarlGrey.

Same as Appium, we set configuration first.

And additional configuration in package file.

Test are written the same way, instead of using Appium API, we use Detox capabilities and limitations. Check links in the end for detailed documentation on setup and reference.

Gray-box testing. Our application and access to internal structure.

What I Like about Detox

  • Made by Wix for React Native.
  • JavaScript focused.
  • Gray box testing (there’s connection between tests and internal processes).
  • Works in sync with the app. Not so flaky.

What I Dislike about Detox

  • Capabilities are not wide as Appium
  • Smaller community.

Flaky, flakey, flakiness

Despite Detox using Gray box tests, it’s still flaky. Test I wrote with text input and swipe gesture for some unknown reason 1 of 10 times failed. You can’t be 100% sure in UI tests.

Speed

Appium will be slower because of manual “sleep” commands, Detox in this case wins as it automatically continues action as soon as one is finished. Overall I would not make any conclusions yet until I run large amount of tests. In small 30 second tests and basic setup for this article Detox performed seconds faster. In terms of iOS vs Android, I tried several tests on both platforms on both frameworks it took +- same amount of time to run the tests. Just be ready that it takes much more time than usual unit tests.

What to choose

Myself I’m still exploring both of these frameworks and it will take time to fully understand both, but for now as a JavaScript developer I pick Detox.

Try both. Luckily it’s only two of them. It really depends on the app you are developing and structure of you team.

UI tests that will be used only in the team of developers, I would suggest Detox. In long and complicated end-to-end tests, because of wider API capabilities as well as support by automated platforms like BrowserStack, AWS DeviceFarm and MS AppCenter I would stick with Appium. It’s for now.

Useful links

Appium website. You’ll find stuff you need from top menu.
http://appium.io

Detox docs.
https://github.com/wix/Detox/tree/master/docs

Detox: Gray Box End to End Testing Framework for Mobile Apps by Rotem Mizrachi-Meidan.
https://hackernoon.com/detox-gray-box-end-to-end-testing-framework-for-mobile-apps-196ccd9564ce

Detox presentation from Wix developer Rotem Mizrachi-Meidan.
https://www.youtube.com/watch?v=GgFFeI70PWw

Detox: getting started
https://github.com/wix/Detox/blob/master/docs/Introduction.GettingStarted.md

In case you didn’t know, there’s testID property in React Native.
https://facebook.github.io/react-native/docs/view#testid

--

--