End-to-end testing in React Native

Write cross-platform end-to-end tests in JavascriptPhoto by freestocks on UnsplashWriting tests for the code has been an essential part of programming nowadays. There are different types of software testing methodologies, such as unit tests, integratio…


This content originally appeared on Level Up Coding - Medium and was authored by Tarik

Write cross-platform end-to-end tests in Javascript

Photo by freestocks on Unsplash

Writing tests for the code has been an essential part of programming nowadays. There are different types of software testing methodologies, such as unit tests, integration tests, and end-to-end tests. This article will cover how we can apply end-to-end testing on a simple react-native app.

We will be using Detox library which is developed and maintained by the Wix team.

The app is pretty straightforward! It allows users to like their favorite Nintendo 64 app. That said, there is actually one certain behavior to test in the app. Like functionality!

User Story

Let’s list all of what can be the user actions for this functionality:

  1. User opens the app.
  2. User sees the game card, and the game card has a like button and a total number of likes text available on it. (To compare the text after the user action)
  3. User presses on the like button.
  4. User notices that like text changed. In this case, the number of likes is increased by one.
CAVEAT: This user story can be considered an integration test in theory. Yet since the app itself is only responsible for allowing users to like their game, it is treated as end-to-end testing.

Code

We will be generating our code whilst we walk through the user stories in order. Each code block will eventually correspond to a specific user story.

  1. User opens the app.

2. User sees the game card, and the game card has a like button and a total number of likes text available on it. (To compare the text after the user action)

3. User presses on the like button.

4. User notices that like text changed. In this case, the number of likes is increased by one.

Full code

Demo

Let’s see everything in action.

This article has covered the preliminaries of end-to-end testing in react-native apps. For the sake of simplicity, the app itself is basic enough to demonstrate fundamental aspects of end-to-end testing. Indeed, it can be more convoluted than this one in real-life/production applications.

You can take a look at the final source code of this app using the link below.

Have a bug-free day everyone!

Github source code

Level Up Coding

Thanks for being a part of our community! Before you go:

🚀👉 Join the Level Up talent collective and find an amazing job


End-to-end testing in React Native was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Tarik


Print Share Comment Cite Upload Translate Updates
APA

Tarik | Sciencx (2022-11-08T12:01:21+00:00) End-to-end testing in React Native. Retrieved from https://www.scien.cx/2022/11/08/end-to-end-testing-in-react-native/

MLA
" » End-to-end testing in React Native." Tarik | Sciencx - Tuesday November 8, 2022, https://www.scien.cx/2022/11/08/end-to-end-testing-in-react-native/
HARVARD
Tarik | Sciencx Tuesday November 8, 2022 » End-to-end testing in React Native., viewed ,<https://www.scien.cx/2022/11/08/end-to-end-testing-in-react-native/>
VANCOUVER
Tarik | Sciencx - » End-to-end testing in React Native. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/08/end-to-end-testing-in-react-native/
CHICAGO
" » End-to-end testing in React Native." Tarik | Sciencx - Accessed . https://www.scien.cx/2022/11/08/end-to-end-testing-in-react-native/
IEEE
" » End-to-end testing in React Native." Tarik | Sciencx [Online]. Available: https://www.scien.cx/2022/11/08/end-to-end-testing-in-react-native/. [Accessed: ]
rf:citation
» End-to-end testing in React Native | Tarik | Sciencx | https://www.scien.cx/2022/11/08/end-to-end-testing-in-react-native/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.