Skip to content

Commit acfe867

Browse files
committed
Crashlytics smoke tests
One test validates the Analytics integration; the rest are simple stubbs for now.
1 parent c816404 commit acfe867

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

smoke-tests/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ buildscript {
2525
dependencies {
2626
classpath "com.android.tools.build:gradle:3.4.3"
2727
classpath "com.google.gms:google-services:4.3.0"
28+
classpath "com.google.firebase:firebase-crashlytics-gradle:2.7.0"
2829
}
2930
}
3031

@@ -70,6 +71,7 @@ dependencies {
7071
implementation "com.google.firebase:firebase-auth"
7172
implementation "com.google.firebase:firebase-common"
7273
implementation "com.google.firebase:firebase-config"
74+
implementation "com.google.firebase:firebase-crashlytics"
7375
implementation "com.google.firebase:firebase-database"
7476
implementation "com.google.firebase:firebase-dynamic-links"
7577
implementation "com.google.firebase:firebase-firestore"
@@ -101,3 +103,4 @@ clean.doLast {
101103
}
102104

103105
apply plugin: "com.google.gms.google-services"
106+
apply plugin: "com.google.firebase.crashlytics"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.testing;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import com.google.firebase.analytics.connector.AnalyticsConnector;
20+
import com.google.firebase.crashlytics.FirebaseCrashlytics;
21+
22+
import androidx.test.runner.AndroidJUnit4;
23+
import com.google.firebase.inject.Deferred;
24+
import com.google.firebase.inject.Deferred.DeferredHandler;
25+
import com.google.firebase.inject.Provider;
26+
import java.lang.reflect.Field;
27+
import java.util.concurrent.CountDownLatch;
28+
import java.util.concurrent.TimeUnit;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
32+
@RunWith(AndroidJUnit4.class)
33+
public final class CrashlyticsTest {
34+
35+
@Test
36+
public void analyticsIntegration() {
37+
// There's no public API to validate that the analytics connector is working, so we'll find the
38+
// reference to the Deferred AnalyticsConnector via reflection and assert that it is available.
39+
try {
40+
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
41+
Field analyticsProxyField =
42+
crashlytics.getClass().getDeclaredField("analyticsDeferredProxy");
43+
analyticsProxyField.setAccessible(true);
44+
Object analyticsProxy = analyticsProxyField.get(crashlytics);
45+
Field analyticsConnectorField =
46+
analyticsProxy.getClass().getDeclaredField("analyticsConnectorDeferred");
47+
analyticsConnectorField.setAccessible(true);
48+
Deferred<AnalyticsConnector> analyticsConnector =
49+
(Deferred<AnalyticsConnector>)analyticsConnectorField.get(analyticsProxy);
50+
51+
final CountDownLatch latch = new CountDownLatch(1);
52+
analyticsConnector.whenAvailable(new DeferredHandler<AnalyticsConnector>() {
53+
@Override
54+
public void handle(Provider<AnalyticsConnector> provider) {
55+
latch.countDown();
56+
}
57+
});
58+
59+
// Wait up to 2 seconds, though it should be immediately available
60+
latch.await(2000, TimeUnit.MILLISECONDS);
61+
assertThat(latch.getCount()).isEqualTo(0);
62+
63+
} catch (Exception e) {
64+
throw new RuntimeException(e);
65+
}
66+
}
67+
68+
@Test
69+
public void setCustomKeys() {
70+
// For now, simply validate that the API does not throw any exception. A more robust functional
71+
// test could be implemented via reflection or monitoring logcat.
72+
FirebaseCrashlytics.getInstance().setCustomKey("TestKey", "TestValue");
73+
}
74+
75+
@Test
76+
public void log() {
77+
// For now, simply validate that the API does not throw any exception. A more robust functional
78+
// test could be implemented via reflection or monitoring logcat.
79+
FirebaseCrashlytics.getInstance().log("This is a log message");
80+
}
81+
82+
@Test
83+
public void didCrashOnPreviousExecution() {
84+
assertThat(FirebaseCrashlytics.getInstance().didCrashOnPreviousExecution()).isFalse();
85+
}
86+
}
87+

smoke-tests/src/main/java/com/google/firebase/testing/TestSuite.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@RunWith(Suite.class)
2626
@Suite.SuiteClasses({
2727
BuildOnlyTest.class,
28+
CrashlyticsTest.class,
2829
DatabaseTest.class,
2930
DynamicLinksTest.class,
3031
FirestoreTest.class,

0 commit comments

Comments
 (0)