Skip to content

Commit a2ce65b

Browse files
authored
Move crashlytics ktx test to androidTest (#1639)
* Move crashlytics ktx test to androidTest
1 parent 2ae7181 commit a2ce65b

File tree

6 files changed

+116
-85
lines changed

6 files changed

+116
-85
lines changed

firebase-crashlytics/ktx/ktx.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ plugins {
1919

2020
firebaseLibrary {
2121
releaseWith project(':firebase-crashlytics')
22+
testLab.enabled = true
2223
publishJavadoc = true
2324
publishSources = true
2425
}
@@ -37,6 +38,7 @@ android {
3738
test.java {
3839
srcDir 'src/test/kotlin'
3940
}
41+
androidTest.java.srcDirs += 'src/androidTest/kotlin'
4042
}
4143
testOptions.unitTests.includeAndroidResources = true
4244
}
@@ -54,4 +56,17 @@ dependencies {
5456
testImplementation 'junit:junit:4.12'
5557
testImplementation "com.google.truth:truth:$googleTruthVersion"
5658
testImplementation 'org.mockito:mockito-core:2.25.0'
59+
60+
androidTestImplementation 'junit:junit:4.12'
61+
androidTestImplementation "com.google.truth:truth:$googleTruthVersion"
62+
androidTestImplementation 'androidx.test:runner:1.2.0'
63+
androidTestImplementation 'androidx.test:core:1.2.0'
5764
}
65+
66+
// ==========================================================================
67+
// Copy from here down if you want to use the google-services plugin in your
68+
// androidTest integration tests.
69+
// ==========================================================================
70+
ext.packageName = "com.google.firebase.crashlytics.ktx"
71+
apply from: '../../gradle/googleServices.gradle'
72+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.google.firebase.crashlytics.ktx">
3+
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
4+
<!--<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />-->
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
<application>
7+
<uses-library android:name="android.test.runner" />
8+
</application>
9+
10+
<instrumentation
11+
android:name="androidx.test.runner.AndroidJUnitRunner"
12+
android:targetPackage="com.google.firebase.crashlytics.ktx" />
13+
</manifest>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2020 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.crashlytics.ktx
16+
17+
import androidx.test.InstrumentationRegistry
18+
import androidx.test.runner.AndroidJUnit4
19+
import com.google.common.truth.Truth.assertThat
20+
import com.google.firebase.FirebaseApp
21+
import com.google.firebase.crashlytics.FirebaseCrashlytics
22+
import com.google.firebase.ktx.Firebase
23+
import com.google.firebase.ktx.app
24+
import com.google.firebase.ktx.initialize
25+
import com.google.firebase.platforminfo.UserAgentPublisher
26+
import org.junit.AfterClass
27+
import org.junit.BeforeClass
28+
import org.junit.Test
29+
import org.junit.runner.RunWith
30+
31+
@RunWith(AndroidJUnit4::class)
32+
class CrashlyticsTests {
33+
companion object {
34+
lateinit var app: FirebaseApp
35+
36+
@BeforeClass @JvmStatic fun setup() {
37+
app = Firebase.initialize(InstrumentationRegistry.getContext())!!
38+
}
39+
40+
@AfterClass @JvmStatic fun cleanup() {
41+
app.delete()
42+
}
43+
}
44+
45+
@Test
46+
fun firebaseCrashlyticsDelegates() {
47+
assertThat(Firebase.crashlytics).isSameInstanceAs(FirebaseCrashlytics.getInstance())
48+
}
49+
50+
@Test
51+
fun testDataCall() {
52+
assertThat("hola").isEqualTo("hola")
53+
}
54+
}
55+
56+
@RunWith(AndroidJUnit4::class)
57+
class LibraryVersionTest {
58+
companion object {
59+
lateinit var app: FirebaseApp
60+
61+
@BeforeClass @JvmStatic fun setup() {
62+
app = Firebase.initialize(InstrumentationRegistry.getContext())!!
63+
}
64+
65+
@AfterClass @JvmStatic fun cleanup() {
66+
app.delete()
67+
}
68+
}
69+
70+
@Test
71+
fun libraryRegistrationAtRuntime() {
72+
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
73+
assertThat(publisher.userAgent).contains(LIBRARY_NAME)
74+
}
75+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2019 Google LLC
4+
-->
5+
6+
<resources
7+
xmlns:tools="http://schemas.android.com/tools">
8+
9+
<string name="com.crashlytics.RequireBuildId" tools:ignore="UnusedResources">false</string>
10+
11+
</resources>

firebase-crashlytics/ktx/src/main/kotlin/com/google/firebase/crashlytics/ktx/KeyValueBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics
1818

1919
/** Helper class to enable fluent syntax in [setCustomKeys] */
2020
class KeyValueBuilder(
21-
private val crashlytics: FirebaseCrashlytics
21+
private val crashlytics: FirebaseCrashlytics
2222
) {
2323

2424
/** Sets a custom key and value that are associated with reports. */
@@ -38,4 +38,4 @@ class KeyValueBuilder(
3838

3939
/** Sets a custom key and value that are associated with reports. */
4040
fun key(key: String, value: String) = crashlytics.setCustomKey(key, value)
41-
}
41+
}

firebase-crashlytics/ktx/src/test/java/com/google/firebase/crashlytics/ktx/CrashlyticsTests.kt

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)