TestingBot Blog

TestingBot provides a cloud of browsers and devices, ready to run your Automated, Live and Visual tests.

< Back to Blog Overview

React Native testing

2019-10-03


React Native makes it easy to create mobile applications for both iOS and Android.

Developers create the mobile app with Javascript and then have React Native compile these into native mobile apps. The mobile apps that React Native creates look and behave exactly as apps created with Java/Kotlin or Objective-C/Swift.


The project was created by Facebook and is still maintained by Facebook, it regularly receives updates and fixes. The main advantages of using React Native:



In this article, we'll go through the steps necessary to create an application, modify it for automated testing and then test it automatically via Appium on TestingBot.

Creating a React Native Application

To get started, please install React Native:


npm install -g react-native-cli

Once you have installed React Native, it is time to create our project:
react-native init TestingBotDemo
cd ios && pod install


This will create a skeleton of files and set everything up for you to test/create your mobile application.


To get started, let's create our main component. We'll create a basic calculator that will require two numbers and show you the sum of those numbers.



This example App creates a view with 2 input fields (InputA and InputB). Once the user puts in some numbers, the state will update and the sum will be shown in Sum.

Preparing your React Native App for UI Testing

The important part we want to focus on here are the testID and accessibilityLabel attributes. These are the attributes that allows your Automated Test to quickly locate the input fields.


For iOS tests with XCUITest, the testID makes it much easier to locate an element in your tests. You can use the value specified in this attribute as a locator for your Appium tests. This works much better than using XPath for locating elements, because an XPath expression can become complicated very fast, and is prone to change.


Android testing via Espresso or UIAutomator does not use this testID attribute. Instead, you can use the accessibilityLabel in your tests for Android tests.

Testing your React Native app with Appium

Now that we have prepared our app for testing, we can run a test that will add some simple numbers and verify if the calculator works:


This will launch the app on a physical Android device in the TestingBot datacenter. The test will locate both inputs, put in a number, and then verify if sum is correct.


We have a lot of more documentation on mobile app testing in our documentation section.

Conclusion

React Native provides an easy framework to quickly write mobile apps for both iOS and Android. It has very good test frameworks, such as Jest, to create functional and unit tests with snapshots.


It is important to write end-to-end tests, testing the UI and functionality of your app on real devices, before your release it on the App Store. With Appium testing, automated tests will mimic the action of your end users; tapping, swiping, etc.


TestingBot provides mobile devices (real devices and emulators) to run your tests on a variety of configurations (different OS versions and device specs).


If you'd like to get started with mobile app testing, please sign up for a free account and try our easy to follow tutorial on mobile app testing with Appium.

< Back to Blog Overview

Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.