Skip to content

Commit

Permalink
add Detox integrations to Android RNTester app
Browse files Browse the repository at this point in the history
Summary:
This diff adds required Detox integrations to the RNTester app to be able to run Detox end-to-end tests on the Android version of the app.

* Instructions at https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md were followed.
* The `minSdkVersion` version for the app was bumped to 18, as required by Detox.
* I also added build and test configurations in `package.json`
*  The debug app is able to run some of the existing tests, but the release app instacrashes. I do not know the reason for the instacrash at this time.
* CI integrations to build and test the Android app will be added in future diffs

Changelog:
[Internal] add Detox integrations to the RNTester Android app

Reviewed By: TheSavior

Differential Revision: D19566834

fbshipit-source-id: 5dd506bbdbb426a5db18146e5dc7c450a27b1d0c
  • Loading branch information
cs01 authored and facebook-github-bot committed Feb 11, 2020
1 parent 6ba2aee commit 29d3dfb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
10 changes: 9 additions & 1 deletion RNTester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ android {

defaultConfig {
applicationId "com.facebook.react.uiapp"
minSdkVersion 16
minSdkVersion 18
targetSdkVersion 29
versionCode 1
versionName "1.0"
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
signingConfigs {
release {
Expand All @@ -149,6 +151,8 @@ android {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
// Detox-specific additions to pro-guard
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
}
}
}
Expand Down Expand Up @@ -187,4 +191,8 @@ dependencies {
} else {
jscImplementation 'org.webkit:android-jsc:+'
}

// Use detox test library
androidTestImplementation('com.wix:detox:+') { transitive = true }
androidTestImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// This uses instructions from
// https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#4-create-android-test-class

package com.facebook.react.uiapp;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import com.wix.detox.Detox;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class DetoxTest {

@Rule
public ActivityTestRule<RNTesterActivity> mActivityRule =
new ActivityTestRule<>(RNTesterActivity.class, false, false);

@Test
public void runDetoxTests() {
Detox.runTests(mActivityRule);
}
}
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ allprojects {
maven {
url = uri("$rootDir/node_modules/jsc-android/dist")
}
maven {
// https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md
// All of Detox's artifacts are provided via the npm module
url = uri("$rootDir/node_modules/detox/Detox-android")
}
mavenLocal()
google()
jcenter()
Expand Down
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@
"runner-config": "RNTester/e2e/config.json",
"specs": "",
"configurations": {
"android.emu.release": {
"binaryPath": "RNTester/android/app/build/outputs/apk/hermes/release/app-hermes-x86-release.apk",
"testBinaryPath": "RNTester/android/app/build/outputs/apk/androidTest/hermes/release/app-hermes-release-androidTest.apk",
"build":
"./gradlew RNTester:android:app:assembleRelease RNTester:android:app:assembleAndroidTest -DtestBuildType=release",
"type": "android.emulator",
"device": {
"avdName": "Nexus_6_API_29"
}
},
"android.emu.debug": {
"binaryPath": "RNTester/android/app/build/outputs/apk/hermes/debug/app-hermes-x86-debug.apk",
"testBinaryPath": "RNTester/android/app/build/outputs/apk/androidTest/hermes/debug/app-hermes-debug-androidTest.apk",
"build": "./gradlew RNTester:android:app:assembleDebug RNTester:android:app:assembleAndroidTest -DtestBuildType=debug",
"type": "android.emulator",
"device": {
"avdName": "Nexus_6_API_29"
}
},
"ios.sim.release": {
"binaryPath": "RNTester/build/Build/Products/Release-iphonesimulator/RNTester.app/",
"build": "xcodebuild -workspace RNTester/RNTesterPods.xcworkspace -scheme RNTester -configuration Release -sdk iphonesimulator -derivedDataPath RNTester/build -UseModernBuildSystem=NO -quiet",
Expand Down
4 changes: 3 additions & 1 deletion template/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ buildscript {
google()
jcenter()
}
ext.kotlinVersion = '1.3.0'
dependencies {
classpath("com.android.tools.build:gradle:3.5.3")

// for Detox
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down

0 comments on commit 29d3dfb

Please sign in to comment.