Skip to content

Commit 29d3dfb

Browse files
cs01facebook-github-bot
authored andcommitted
add Detox integrations to Android RNTester app
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
1 parent 6ba2aee commit 29d3dfb

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

RNTester/android/app/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ android {
120120

121121
defaultConfig {
122122
applicationId "com.facebook.react.uiapp"
123-
minSdkVersion 16
123+
minSdkVersion 18
124124
targetSdkVersion 29
125125
versionCode 1
126126
versionName "1.0"
127+
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
128+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
127129
}
128130
signingConfigs {
129131
release {
@@ -149,6 +151,8 @@ android {
149151
minifyEnabled enableProguardInReleaseBuilds
150152
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
151153
signingConfig signingConfigs.release
154+
// Detox-specific additions to pro-guard
155+
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
152156
}
153157
}
154158
}
@@ -187,4 +191,8 @@ dependencies {
187191
} else {
188192
jscImplementation 'org.webkit:android-jsc:+'
189193
}
194+
195+
// Use detox test library
196+
androidTestImplementation('com.wix:detox:+') { transitive = true }
197+
androidTestImplementation 'junit:junit:4.12'
190198
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// This uses instructions from
9+
// https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#4-create-android-test-class
10+
11+
package com.facebook.react.uiapp;
12+
13+
import androidx.test.ext.junit.runners.AndroidJUnit4;
14+
import androidx.test.filters.LargeTest;
15+
import androidx.test.rule.ActivityTestRule;
16+
import com.wix.detox.Detox;
17+
import org.junit.Rule;
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
21+
@RunWith(AndroidJUnit4.class)
22+
@LargeTest
23+
public class DetoxTest {
24+
25+
@Rule
26+
public ActivityTestRule<RNTesterActivity> mActivityRule =
27+
new ActivityTestRule<>(RNTesterActivity.class, false, false);
28+
29+
@Test
30+
public void runDetoxTests() {
31+
Detox.runTests(mActivityRule);
32+
}
33+
}

build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ allprojects {
2525
maven {
2626
url = uri("$rootDir/node_modules/jsc-android/dist")
2727
}
28+
maven {
29+
// https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md
30+
// All of Detox's artifacts are provided via the npm module
31+
url = uri("$rootDir/node_modules/detox/Detox-android")
32+
}
2833
mavenLocal()
2934
google()
3035
jcenter()

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@
159159
"runner-config": "RNTester/e2e/config.json",
160160
"specs": "",
161161
"configurations": {
162+
"android.emu.release": {
163+
"binaryPath": "RNTester/android/app/build/outputs/apk/hermes/release/app-hermes-x86-release.apk",
164+
"testBinaryPath": "RNTester/android/app/build/outputs/apk/androidTest/hermes/release/app-hermes-release-androidTest.apk",
165+
"build":
166+
"./gradlew RNTester:android:app:assembleRelease RNTester:android:app:assembleAndroidTest -DtestBuildType=release",
167+
"type": "android.emulator",
168+
"device": {
169+
"avdName": "Nexus_6_API_29"
170+
}
171+
},
172+
"android.emu.debug": {
173+
"binaryPath": "RNTester/android/app/build/outputs/apk/hermes/debug/app-hermes-x86-debug.apk",
174+
"testBinaryPath": "RNTester/android/app/build/outputs/apk/androidTest/hermes/debug/app-hermes-debug-androidTest.apk",
175+
"build": "./gradlew RNTester:android:app:assembleDebug RNTester:android:app:assembleAndroidTest -DtestBuildType=debug",
176+
"type": "android.emulator",
177+
"device": {
178+
"avdName": "Nexus_6_API_29"
179+
}
180+
},
162181
"ios.sim.release": {
163182
"binaryPath": "RNTester/build/Build/Products/Release-iphonesimulator/RNTester.app/",
164183
"build": "xcodebuild -workspace RNTester/RNTesterPods.xcworkspace -scheme RNTester -configuration Release -sdk iphonesimulator -derivedDataPath RNTester/build -UseModernBuildSystem=NO -quiet",

template/android/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ buildscript {
1111
google()
1212
jcenter()
1313
}
14+
ext.kotlinVersion = '1.3.0'
1415
dependencies {
1516
classpath("com.android.tools.build:gradle:3.5.3")
16-
17+
// for Detox
18+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
1719
// NOTE: Do not place your application dependencies here; they belong
1820
// in the individual module build.gradle files
1921
}

0 commit comments

Comments
 (0)