Giter Club home page Giter Club logo

boilerplate-react-native-detox's Introduction

boilerplate-react-native-detox

GETTING STARTED
  1. Clone the repository
  2. yarn run build:test (which actually runs detox build in package.json)
  3. detox test

SETUP GUIDE
1. Initialise React Native and do necessary setup for typescript etc if needed (or consider an already ready app)
npx react-native init boilerplateReactNativeDetox
2. Setup Detox

Note: Issues that may occur:

  • Installing Detox (postinstall script may fail)
    export DETOX_DISABLE_POSTINSTALL=true
    
  1. Install Dependencies:

    a. Install the latest version of Homebrew

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    b. Install Node.js

    brew update && brew install node
    

    c. Install applesimutils

    brew tap wix/brew
    brew install applesimutils
    

    d. Install Detox command line tools (detox-cli)

    npm install -g detox-cli
    
  2. Add Detox to your project

    a. Install detox

    yarn add detox @types/detox jest @types/jest -D
    

    b. Add Detox config to package.json

    "detox": {
        "configurations": {
            "android.emu.debug": {
                "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
                "build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
                "type": "android.emulator",
                "device": {
                    "avdName": "Nexus_6_API_27"
                }
            }
        },
        "test-runner": "jest"
    }
    
  3. Make configuration changes for detox to work a. Add Detox dependency to an Android project. In your root buildscript (i.e. build.gradle), register both google() and detox as repository lookup points in all projects:

    // Note: add the 'allproject' section if it doesn't exist
    allprojects {
        repositories {
            // ...
            google()
            maven {
                // All of Detox' artifacts are provided via the npm module
                url "$rootDir/../node_modules/detox/Detox-android"
            }
        }
    }
    

    In your app's buildscript (i.e. app/build.gradle) add this in dependencies section:

    dependencies {
        // ...
        implementation "androidx.annotation:annotation:1.1.0"
        androidTestImplementation('com.wix:detox:+') { transitive = true }
        androidTestImplementation 'junit:junit:4.12'
    }
    

    In your app's buildscript (i.e. app/build.gradle) add this to the defaultConfig subsection:

    android {
        // ...
        defaultConfig {
            // ...
            testBuildType System.getProperty('testBuildType', 'debug')  // This will later be used to control the test apk build type
            testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
        }
    }
    

    Please be aware that the minSdkVersion in app's build.gadle needs to be at least 18.

    b. Add Kotlin. If your project does not already support Kotlin, add the Kotlin Gradle-plugin to your classpath in the root build-script (i.e.android/build.gradle):

    buildscript {
        // ...
        ext: {
            // ...
            kotlinVersion = "1.3.10"
        }
    
        dependencies: {
            // ...
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        }
    }
    

    c. Create Android Test class. Add the file android/app/src/androidTest/java/com/[your.package]/DetoxTest.java and fill as in:

    package com.example;
    
    import com.wix.detox.Detox;
    
    import org.junit.Rule;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    
    import androidx.test.ext.junit.runners.AndroidJUnit4;
    import androidx.test.filters.LargeTest;
    import androidx.test.rule.ActivityTestRule;
    
    @RunWith(AndroidJUnit4.class)
    @LargeTest
    public class DetoxTest {
    
        @Rule
        public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
    
        @Test
        public void runDetoxTests() {
            Detox.runTests(mActivityRule);
        }
    }
    

    Don't forget to change the package name to your project's.

  4. Build and Run the tests:

detox init -r jest
detox build
detox test

boilerplate-react-native-detox's People

Contributors

avaneeshtripathi avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.