Skip to content

Commit f611a43

Browse files
test: add integration tests (#368)
Co-authored-by: Joonas Kerttula <[email protected]>
1 parent bf50530 commit f611a43

File tree

24 files changed

+2337
-69
lines changed

24 files changed

+2337
-69
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ jobs:
8888
runs-on: ubuntu-latest
8989
timeout-minutes: 30
9090
steps:
91-
- name: Checkout
92-
uses: actions/checkout@v4
91+
- name: Placeholder Test Step
92+
run: echo "No tests to run yet" && true
93+
# TODO: build test orchestration for Android and iOS and run detox tests on both platforms.
94+
# - name: Checkout
95+
# uses: actions/checkout@v4
9396

94-
- name: Setup
95-
uses: ./.github/actions/setup
97+
# - name: Setup
98+
# uses: ./.github/actions/setup
9699

97-
- name: Run unit tests
98-
run: yarn test --maxWorkers=2 --coverage
100+
# - name: Run unit tests
101+
# run: yarn test --maxWorkers=2 --coverage
99102

100103
build-library:
101104
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,39 @@ Please peruse the
109109
[Typescript style guide](https://google.github.io/styleguide/tsguide.html), [Java style guide](https://google.github.io/styleguide/javaguide.html), and [Objective-C style guide](https://google.github.io/styleguide/objcguide.html) before
110110
working on anything non-trivial. These guidelines are intended to
111111
keep the code consistent and avoid common pitfalls.
112+
113+
## 6. Running tests
114+
115+
Google Maps React Native Navigation package has integration tests.
116+
117+
### Integration tests
118+
119+
Integration tests are responsible for ensuring that the plugin works against the native Navigation SDK for both Android and iOS platforms. Detox along with example application is used for the integration tests. "Integration tests must accompany the implementation of all new features.
120+
To run the test you must first install and setup detox. Please follow the guide here:
121+
https://wix.github.io/Detox/docs/introduction/environment-setup
122+
123+
Build the tests using detox-cli in the example folder:
124+
125+
iOS:
126+
```bash
127+
detox build --configuration ios.sim.release
128+
```
129+
130+
Android:
131+
```bash
132+
detox build --configuration android.emu.release
133+
```
134+
135+
Google Maps React Native Navigation SDK integration tests can be run with the following command:
136+
137+
iOS
138+
```bash
139+
yarn run example test:ios-release
140+
```
141+
142+
Android:
143+
```bash
144+
yarn run example detox:test:android-release
145+
```
146+
147+
When adding new tests, you need to first add the detox part in the [e2e folder](./example/e2e) and then the actual logical part of the test in the [integration tests page](./example/src/screens/IntegrationTestsScreen.tsx) of the example app.

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ android {
4747
}
4848

4949
defaultConfig {
50-
minSdkVersion 23
50+
minSdkVersion 24
5151
targetSdkVersion 34
5252
versionCode 1
5353
// get version name from package.json version
@@ -56,7 +56,7 @@ android {
5656

5757
buildTypes {
5858
release {
59-
minifyEnabled false
59+
minifyEnabled true
6060
}
6161
}
6262

android/src/main/java/com/google/android/react/navsdk/AndroidAutoBaseScreen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import androidx.lifecycle.Lifecycle;
3535
import androidx.lifecycle.LifecycleObserver;
3636
import androidx.lifecycle.LifecycleOwner;
37+
import com.facebook.proguard.annotations.DoNotStrip;
3738
import com.facebook.react.bridge.ReadableMap;
3839
import com.google.android.gms.maps.CameraUpdate;
3940
import com.google.android.gms.maps.CameraUpdateFactory;
@@ -48,6 +49,7 @@
4849
// For more information on using Android Auto with the Google Navigation SDK, refer to the official
4950
// documentation:
5051
// https://developers.google.com/maps/documentation/navigation/android-sdk/android-auto
52+
@DoNotStrip
5153
public abstract class AndroidAutoBaseScreen extends Screen
5254
implements SurfaceCallback, INavigationViewController {
5355
private static final String VIRTUAL_DISPLAY_NAME = "AndroidAutoNavScreen";

android/src/main/java/com/google/android/react/navsdk/Package.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package com.google.android.react.navsdk;
1515

16+
import com.facebook.proguard.annotations.DoNotStrip;
1617
import com.facebook.react.ReactPackage;
1718
import com.facebook.react.bridge.NativeModule;
1819
import com.facebook.react.bridge.ReactApplicationContext;
@@ -21,6 +22,7 @@
2122
import java.util.Arrays;
2223
import java.util.List;
2324

25+
@DoNotStrip
2426
public class Package implements ReactPackage {
2527

2628
private NavViewManager mNavViewManager;

example/.detoxrc.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** @type {Detox.DetoxConfig} */
18+
module.exports = {
19+
testRunner: {
20+
args: {
21+
$0: 'jest',
22+
config: 'e2e/jest.config.js',
23+
},
24+
jest: {
25+
setupTimeout: 120000,
26+
},
27+
},
28+
apps: {
29+
'ios.debug': {
30+
type: 'ios.app',
31+
binaryPath:
32+
'ios/build/Build/Products/Debug-iphonesimulator/SampleApp.app',
33+
build:
34+
'xcodebuild -workspace ios/SampleApp.xcworkspace -scheme SampleApp -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build',
35+
},
36+
'ios.release': {
37+
type: 'ios.app',
38+
binaryPath:
39+
'ios/build/Build/Products/Release-iphonesimulator/SampleApp.app',
40+
build:
41+
'xcodebuild -workspace ios/SampleApp.xcworkspace -scheme SampleApp -configuration Release -sdk iphonesimulator -derivedDataPath ios/build',
42+
},
43+
'android.debug': {
44+
type: 'android.apk',
45+
binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
46+
build:
47+
'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
48+
reversePorts: [8081],
49+
},
50+
'android.release': {
51+
type: 'android.apk',
52+
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
53+
build:
54+
'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
55+
},
56+
},
57+
devices: {
58+
simulator: {
59+
type: 'ios.simulator',
60+
device: {
61+
type: 'iPhone 16 Pro',
62+
},
63+
},
64+
attached: {
65+
type: 'android.attached',
66+
device: {
67+
adbName: '.*',
68+
},
69+
},
70+
emulator: {
71+
type: 'android.emulator',
72+
device: {
73+
avdName: 'Pixel_8_API_35',
74+
},
75+
},
76+
},
77+
configurations: {
78+
'ios.sim.debug': {
79+
device: 'simulator',
80+
app: 'ios.debug',
81+
},
82+
'ios.sim.release': {
83+
device: 'simulator',
84+
app: 'ios.release',
85+
},
86+
'android.att.debug': {
87+
device: 'attached',
88+
app: 'android.debug',
89+
},
90+
'android.att.release': {
91+
device: 'attached',
92+
app: 'android.release',
93+
},
94+
'android.emu.debug': {
95+
device: 'emulator',
96+
app: 'android.debug',
97+
},
98+
'android.emu.release': {
99+
device: 'emulator',
100+
app: 'android.release',
101+
},
102+
},
103+
};

example/android/app/build.gradle

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ react {
7474
/**
7575
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
7676
*/
77-
def enableProguardInReleaseBuilds = false
77+
def enableProguardInReleaseBuilds = true
78+
79+
80+
/**
81+
* Set this to true to enable desugaring if minSdkVersion is set to 34 or below.
82+
* Note that this currently affects Detox testing with release builds and therefore is not enabled by default.
83+
*/
84+
def enableDesugaring = false
7885

7986
/**
8087
* The preferred build flavor of JavaScriptCore (JSC)
@@ -101,6 +108,8 @@ android {
101108
targetSdkVersion rootProject.ext.targetSdkVersion
102109
versionCode 1
103110
versionName "1.0"
111+
testBuildType System.getProperty('testBuildType', 'debug')
112+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
104113
}
105114
signingConfigs {
106115
debug {
@@ -119,17 +128,19 @@ android {
119128
// see https://reactnative.dev/docs/signed-apk-android.
120129
signingConfig signingConfigs.debug
121130
minifyEnabled enableProguardInReleaseBuilds
122-
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
131+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro", "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
123132
}
124133
}
125134
compileOptions {
126-
coreLibraryDesugaringEnabled true
135+
coreLibraryDesugaringEnabled enableDesugaring
127136
sourceCompatibility JavaVersion.VERSION_17
128137
targetCompatibility JavaVersion.VERSION_17
129138
}
130139
}
131140

132141
dependencies {
142+
androidTestImplementation('com.wix:detox:+')
143+
implementation 'androidx.appcompat:appcompat:1.1.0'
133144
// The version of react-native is set by the React Native Gradle Plugin
134145
implementation("com.facebook.react:react-android")
135146

@@ -147,7 +158,7 @@ dependencies {
147158
implementation 'com.google.android.libraries.navigation:navigation:6.0.0'
148159

149160
// Desugar Java 8+ APIs
150-
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.4'
161+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.3'
151162
}
152163

153164
secrets {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.sampleapp;
18+
19+
import androidx.test.ext.junit.runners.AndroidJUnit4;
20+
import androidx.test.filters.LargeTest;
21+
import androidx.test.rule.ActivityTestRule;
22+
import com.wix.detox.Detox;
23+
import com.wix.detox.config.DetoxConfig;
24+
import org.junit.Rule;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
28+
@RunWith(AndroidJUnit4.class)
29+
@LargeTest
30+
public class DetoxTest {
31+
@Rule // (2)
32+
public ActivityTestRule<MainActivity> mActivityRule =
33+
new ActivityTestRule<>(MainActivity.class, false, false);
34+
35+
@Test
36+
public void runDetoxTests() {
37+
DetoxConfig detoxConfig = new DetoxConfig();
38+
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
39+
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
40+
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60);
41+
42+
Detox.runTests(mActivityRule, detoxConfig);
43+
}
44+
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
android:roundIcon="@mipmap/ic_launcher_round"
3434
android:allowBackup="false"
3535
android:theme="@style/AppTheme"
36-
android:supportsRtl="true">
36+
android:supportsRtl="true"
37+
android:networkSecurityConfig="@xml/network_security_config">
3738
<activity
3839
android:name=".MainActivity"
3940
android:label="@string/app_name"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2024 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<network-security-config>
19+
<domain-config cleartextTrafficPermitted="true">
20+
<domain includeSubdomains="true">10.0.2.2</domain>
21+
<domain includeSubdomains="true">localhost</domain>
22+
</domain-config>
23+
</network-security-config>

0 commit comments

Comments
 (0)