Detox vs Appium — What’s best for React Native
In 2018, I was writing End-to-End testing in React Native. Now, in 2023, what has changed? Have the frameworks improved, matured, became more stable or is there a new player on the field?
Use the code “reime005-medium-free” to get a free version of my Ultimate React Native Testing Guide on Gumroad.
When looking on the market (community) side, there is the option to Cavy. I have tried it, and it looks promising, but is more an alternative to the integration tests with the rest-native-testing-library. Concerns that I have with Cavy is the customization that you need on your business logic. Instead of the element query by accessibility label (Appium) or test id (Detox), Cavy relies on React references. Specific device specific functionality is also not provided, due to its JavaScript implementation.
Detox
Detox is an end-to-end testing framework for React Native and native apps. You may run your fully automated E2E tests on a real device, simulator or in a cloud. Your app can be tested as if it would be a real human, clicking and evaluating your app flows. Due to its intelligent app-test synchronization mechanism, which means it monitors app operations, tests are very smooth and reliable. Integration with common test runners like Jest or Mocha is also given.
Appium
As a cross-platform end-to-end testing platform, Appium is, besides Detox, one of the most famous to choose from. Test cases for Android and iOS can be written in different programming languages, due to its architecture. For example, you could write your Selenium based tests in Python.
The Appium Architecture Overview shows the interaction and separation of the different Appium parts. On one side, there is the client. As already mentioned, clients can be implemented in basically any programming language. This is due to the HTTP- and JSON-based communication to the Appium server. Precisely, the client needs to implement the WebDriver protocol. The server is implemented in node.js, which should make installing and developing more straight forward.
Drivers provide the automation for various platforms. They contain the logic of how to automate specific platforms. This means, a platform like Android or iOS can have one or more drivers. They are handled from the Appium server and interact with a simulator or real device.
Detox vs Appium
Detox is grey boxed, due to its capability to synchronize with app-internal actions. Appium is does not have this feature, so it is rather black box.
Appium
- Supports real devices and simulators
- Enables cloud device testing
- Possible to extend with features like visual (regression) testing
- Architecture is based on WebDriver. This opens up the possibility to write tests in other programming languages supported by Selenium like Java, Python, Swift or Kotlin
- You can use the Appium Inspector to inspect your app in a 3D GUI
- Requires a lot of configuration, which can be tricky
- Uses the
accessibilityLabel
to locate elements in your app
Detox
- Supports simulators and real device (only on Android)
- Enables first-class cloud device testing with Genymotion SaaS
- Uses Espresso at its core (Android) and their own native testing for iOS
- Does not rely on WebDriver, but tests can be integrated with any test runner, prominently Jest
- At its core uses web sockets with a proxy server in-between, so their internal architecture is more flexible. Assertions are evaluated directly on the device and sent to the node.js process, giving a performance plus
- Requires you to build an Android test runner APK, that connects to the Detox service
- Uses the
testID
to locate elements in your app
From my perspective, Detox is still the best choice for a React Native E2E testing framework. This is mostly due to its well functioning and easy to integrate tests, as well as its low flakiness thanks to their app-device synchronization system. I also experienced that localizing elements in the app was way more reliable than with Appium.
Appium can be a good option, especially if you want do something specific that is only possible with that framework, or if you like to write tests in different programming languages. Also, using the accessibility label for the wrong reason does not make sense in my opinion. Even performing a swipe can be a complicated action, since you have to program every single step yourself.
My guide “ is now available on Gumroad. In includes 74 pages of content and the full source code of an example React Native app, completely tested with the testing-library, Appium and Detox. Use the code “reime005-medium-free” to get a free version — I would just ask you for a review, that would be great.
My website: https://mariusreimer.com