Skip to content

Commit 895fa7b

Browse files
author
Brian Chen
authored
Add option to run tests against emulator (#540)
Firestore now runs against the emulator by default.
1 parent 1cf5ceb commit 895fa7b

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

.idea/runConfigurations/FirestoreProdIntegrationTest.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Firestore_Integration_Tests.xml renamed to .idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firebase-firestore/firebase-firestore.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ android {
9292
targetCompatibility JavaVersion.VERSION_1_8
9393
}
9494
testOptions.unitTests.includeAndroidResources = true
95+
ext.useProdBackendForTests = false
96+
}
97+
98+
android.libraryVariants.all { variant ->
99+
if (findProperty("useProdBackendForTests")) {
100+
variant.buildConfigField("boolean", "USE_EMULATOR_FOR_TESTS", "false")
101+
} else {
102+
variant.buildConfigField("boolean", "USE_EMULATOR_FOR_TESTS", "true")
103+
}
104+
95105
}
96106

97107
dependencies {

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.android.gms.tasks.TaskCompletionSource;
2727
import com.google.android.gms.tasks.Tasks;
2828
import com.google.firebase.firestore.AccessHelper;
29+
import com.google.firebase.firestore.BuildConfig;
2930
import com.google.firebase.firestore.CollectionReference;
3031
import com.google.firebase.firestore.DocumentReference;
3132
import com.google.firebase.firestore.DocumentSnapshot;
@@ -60,9 +61,9 @@ public class IntegrationTestUtil {
6061
// Whether the integration tests should run against a local Firestore emulator instead of the
6162
// Production environment. Note that the Android Emulator treats "10.0.2.2" as its host machine.
6263
// TODO(mrschmidt): Support multiple envrionments (Emulator, QA, Nightly, Production)
63-
private static final boolean CONNECT_TO_EMULATOR = false;
64+
private static final boolean CONNECT_TO_EMULATOR = BuildConfig.USE_EMULATOR_FOR_TESTS;
6465
private static final String EMULATOR_HOST = "10.0.2.2";
65-
private static final int EMULATOR_PORT = 8081;
66+
private static final int EMULATOR_PORT = 8080;
6667

6768
// Alternate project ID for creating "bad" references. Doesn't actually need to work.
6869
public static final String BAD_PROJECT_ID = "test-project-2";
@@ -94,7 +95,7 @@ public static DatabaseInfo testEnvDatabaseInfo() {
9495
DatabaseId.forProject(provider.projectId()),
9596
"test-persistenceKey",
9697
String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT),
97-
/*sslEnabled=*/ true);
98+
/*sslEnabled=*/ false);
9899
} else {
99100
return new DatabaseInfo(
100101
DatabaseId.forProject(provider.projectId()),
@@ -132,7 +133,7 @@ protected String checkAuthority(String authority) {
132133
SSLCertificateSocketFactory insecureFactory =
133134
(SSLCertificateSocketFactory) SSLCertificateSocketFactory.getInsecure(0, null);
134135
channelBuilder.sslSocketFactory(insecureFactory);
135-
136+
channelBuilder.usePlaintext();
136137
GrpcCallProvider.overrideChannelBuilder(() -> channelBuilder);
137138
} else {
138139
settings.setHost(provider.firestoreHost());

0 commit comments

Comments
 (0)