React Native End-To-End Testing With Detox And GitlabCI – An Easy 4 Step Setup.
Tests to a software development team are like legs to a whole body that bears the weight of technical complexities in the pursuit of good-quality products. Without tests, the fast cycle of iterations and the market’s requirement of quick releases often seen in modern software development will easily overwhelm the business itself. In this blog, you’ll learn how to set up React Native end-to-end testing with Detox and GitlabCI.
Disclaimer: The brands, names, and companies listed in this blog are purely for information and educational purposes. We have no affiliation with the mentioned brands, names, and companies, nor do we endorse the readers from using their services.
React Native End-To-End Testing
The spectrum of software testing spans from static analysis, unit testing, integration testing, and end-to-end testing, in an order of increasing setup difficulty. However, the more difficult end-to-end testing is to set up, the closest it resembles how end-users interact with a product. Hence, end-to-end testing is a “must”, especially in software with complex features and user flow. In the mobile development space, there exist many end-to-end testing solutions that target different frameworks and needs, one of which is Detox.
It happens to be the most suitable React Native end-to-end testing solution since the project is written with React Native as the primary target in the first place. In fact, the React Native website even recommends using Detox as the go-to solution for React Native end-to-end testing.
At Reactron, we use Gitlab as the git management service which also includes a built-in Continuous Integration (CI) system – GitlabCI. Since we maintain many React Native projects, running the tests, especially end-to-end tests automatically in the CI, will ensure that we deliver our projects in the smoothest and highest-quality way possible.
We figured that there hasn’t been any guide that helps development teams set up Detox on their own, so we believe this blog post would serve a good purpose for anyone who is interested in running their Detox end-to-end tests on GitlabCI. We also believe in the openness of the software industry, so we have made our own suggestion to Detox’s documentation website here.
Have questions about Detox’s documentation? Talk to Reactron’s Dev Team for further support
It’s Time For Setup!
We will cover running Detox tests against Android Emulators. We hope the readers should already manage to run their Detox test on their own device. If not, be sure to check out the awesome walkthrough from the Detox team.
First Step: Register Runner
We notice that even though Gitlab provides 2000 minutes of running in their own CI machines for free, those do not support emulation, and therefore, we cannot boot up an emulator to run our tests. Thus, we had to register our own runner (since Gitlab made this their first-class support) with machine support emulations. In this case, we chose Digital Ocean and created a virtual machine there with 8GB of RAM and 4vCPU. Other popular cloud providers that also offer this feature are AWS (with c5 instance types), Google Cloud, and Azure. In addition, we need to register the runner to run in the privileged mode, since invoking virtual machines/emulation requires privileged access to use the KVM module.
1234 [runners.docker] image = “alpine” privileged = true disable_cache = true
Second Step: Get Correct Docker Base Image
GitlabCI’s runner spawns docker containers in order to run the test. Fortunately, the React Native community already provided an awesome docker image specifically for React Native Android. So that will be the base image of this end-to-end job:
123 detox_e2e: stage: test image: reactnativecommunity/react-native-android
Third Step: Don’t Forget The File Watcher
During the setup of the test, we noticed that the default file watcher limit is too low for React Native to make the JS build, so make sure that you bump the file watcher limit before the build starts.
12 before_script: – echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && sysctl -p
Finally: Create An Android Emulator
Now we go to the fun part, the creation of the Android Emulator, and let Detox run the tests in it! We noticed that the React Native Android Docker image provides multiple variants of sdkmanager and avdmanager, which are the command-line tools to get the Android OS image and create emulators. The default variant resides in $ANDROID_HOME/cmdline-tools, which is not the one Detox is expecting (which resides in $ANDROID_HOME/tools/bin). Hence, when detox runs the tests, it cannot find the emulator! In order for Detox to run the tests without issues, we need to make sure that we are using the correct path for the mentioned command-line tools.
1234 script: – mkdir -p /root/.android && touch /root/.android/repositories.cfg – echo yes | $ANDROID_HOME/tools/bin/sdkmanager –channel=0 –verbose “system-images;android-27;default;x86_64” – echo no | $ANDROID_HOME/tools/bin/avdmanager –verbose create avd –force –name “My_Test_Emulator” –package “system-images;android-27;default;x86_64” –sdcard 200M –device 11
Voilà! You’re Good To Go!
After ticking off all the steps in the above setup, the tests should be ready for execution. That’s how you set up React Native end-to-end testing with Detox and GitlabCI!
123 script: – npx detox build -c android.emu.release.ci – npx detox test -c android.emu.release.ci –headless
Psss do you want to save time and painlessly set up React Native End-to-End testing applications? Reactron is a React Native powerhouse with experts who have a burning passion for React Native! We provide everything you need to build a robust application! Check out our services.
Lisätietoja
Tagit
Liiketoimintaprosessi
Tuotekehitys ja suunnittelu |
Erikoisosaaminen
Testaus ja laadunvarmistus | |
Mobiilikehitys | |
Ohjelmistokehitys |
Teknologia
Android | |
React Native |
Tarjonnan tyyppi
Konsultointi | |
Toteutustyö |
Omat tagit
Reactron Technologies - Asiantuntijat ja yhteyshenkilöt
Reactron Technologies - Muita referenssejä
Reactron Technologies - Muita bloggauksia
It- ja ohjelmistoalan työpaikat
- Laura - Development Manager, Operations
- Laura - ICT-asiantuntija
- Laura - IT Manager
- Nordea - Senior Fullstack Developer
- Innofactor Oyj - Business Architect
- Laura - Cloud Engineer
- Laura - UX/UI Designer
Premium-asiakkaiden viimeisimmät referenssit
- SD Worx - Kehitystyö SD Worxin kanssa takaa Clas Ohlsonille parhaat palkanmaksun prosessit kasvun tiellä
- Digiteam Oy - Case Esperi Care Oy: Ketterä kumppanuus vei Esperin verkkosivu-uudistuksen maaliin sujuvasti ja aikataulussa
- Kisko Labs Oy - Howspace Hub - Mukautuva oppimisen hallintajärjestelmä kasvaviin oppimisalustavaatimuksiin
- Kisko Labs Oy - Sanoma Pro: Multimediasisältöjen hallinnan uudistaminen
- Kisko Labs Oy - Svean helppokäyttöinen palvelu asiakkaan verkko-ostosten hallintaan
- Kisko Labs Oy - Yhtenäinen käyttöliittymä luovien alojen ammattilaisille
- Codemate - Digitaalisen murroksen nopeuttaminen Flutterin avulla
Tapahtumat & webinaarit
- 27.11.2024 - Green ICT -ekosysteemitapaaminen III: Ohjelmistojärjestelmien virrankulutuksen mittaaminen ja kasvihuonepäästöjen arviointi
- 27.11.2024 - Digitaalisen asiakaskokemuksen uusi aikakausi
- 28.11.2024 - Webinaari: Keskity myyntityön laatuun!
- 28.11.2024 - Copilot-webinaari – Mielekkäämpää tietotyötä turvallisesti
- 04.12.2024 - Kuinka oikea matka- ja kululaskujärjestelmä tehostaa prosesseja?
- 05.12.2024 - Green ICT VICTIS -hankkeen kick off -tilaisuus
- 15.01.2025 - Datavastuullisuuden valmennus: hanki valmiudet vastuulliseen datan ja tekoälyn hyödyntämiseen
Premium-asiakkaiden viimeisimmät bloggaukset
- Zimple Oy - Pipedrive vai Hubspot? Kumpi kannattaa valita?
- SC Software Oy - Jatkuvat palvelut – asiakaslähtöistä kumppanuutta projekteista ylläpitoon
- Timeless Technology - Ohjelmoitavat logiikat (PLC): Ratkaisevat työkalut automaatioon ControlByWebiltä.
- Kisko Labs Oy - Heroku: Ohjelmistokehittäjän ykköstyökalu skaalautuvien sovellusten rakentamiseen
- SD Worx - Näin luot vakuuttavan Business Casen palkkahallinnon ulkoistukselle
- Timeless Technology - Kyberriskien tunnistaminen Profitap IOTA verkkoanalysaattorin avulla.
- GidiUp Oy - Ai hitto -päivä: Kun sesonki pääsee taas yllättämään
Digitalisaatio & innovaatiot blogimediaBlogimediamme käsittelee tulevaisuuden liiketoimintaa, digitaalisia innovaatioita ja internet-ajan ilmiöitä |