Skip to content

Commit ab9bc35

Browse files
mroberDavid Motsonashvili
authored and
David Motsonashvili
committed
Fix firebase-crashlytics-ktx instrumented tests (#5068)
* Fix firebase-crashlytics-ktx deps * Fix CrashlyticsTests and clean up build file * Make FirebaseCrashlyticsKtxRegistrar internal * Bump health metrics compile sdk * Add versionName version
1 parent 54c1cac commit ab9bc35

File tree

5 files changed

+85
-100
lines changed

5 files changed

+85
-100
lines changed

firebase-crashlytics/ktx/ktx.gradle

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,44 @@
1313
// limitations under the License.
1414

1515
plugins {
16-
id 'firebase-library'
17-
id 'kotlin-android'
16+
id "firebase-library"
17+
id "kotlin-android"
1818
}
1919

2020
firebaseLibrary {
21-
libraryGroup "crashlytics"
22-
testLab.enabled = true
23-
publishJavadoc = true
24-
publishSources = true
21+
libraryGroup "crashlytics"
22+
testLab.enabled = true
23+
publishJavadoc = true
24+
publishSources = true
2525
}
2626

2727
android {
28-
compileSdkVersion 33
29-
defaultConfig {
30-
minSdk 16
31-
multiDexEnabled true
32-
targetSdk 33
33-
versionName version
34-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
35-
}
36-
sourceSets {
37-
main.java.srcDirs += 'src/main/kotlin'
38-
test.java {
39-
srcDir 'src/test/kotlin'
40-
}
41-
androidTest.java.srcDirs += 'src/androidTest/kotlin'
42-
}
43-
testOptions.unitTests.includeAndroidResources = true
28+
compileSdk 33
29+
defaultConfig {
30+
minSdk 16
31+
multiDexEnabled true
32+
targetSdk 33
33+
versionName version
34+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
35+
}
36+
compileOptions {
37+
sourceCompatibility JavaVersion.VERSION_1_8
38+
targetCompatibility JavaVersion.VERSION_1_8
39+
}
40+
kotlinOptions {
41+
jvmTarget = '1.8'
42+
}
43+
testOptions.unitTests.includeAndroidResources = true
4444
}
4545

4646
dependencies {
47-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
48-
49-
implementation 'com.google.firebase:firebase-common:20.3.1'
50-
implementation 'com.google.firebase:firebase-components:17.1.0'
51-
implementation 'com.google.firebase:firebase-common-ktx:20.3.1'
52-
implementation project(':firebase-crashlytics')
53-
implementation 'androidx.annotation:annotation:1.1.0'
54-
55-
testImplementation "org.robolectric:robolectric:$robolectricVersion"
56-
testImplementation 'junit:junit:4.12'
57-
testImplementation "com.google.truth:truth:$googleTruthVersion"
58-
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'
47+
implementation "com.google.firebase:firebase-common-ktx:20.3.2"
48+
implementation "com.google.firebase:firebase-common:20.3.2"
49+
implementation "com.google.firebase:firebase-components:17.1.0"
50+
implementation(libs.androidx.annotation)
51+
implementation project(":firebase-crashlytics")
52+
53+
androidTestImplementation(libs.androidx.test.junit)
54+
androidTestImplementation(libs.androidx.test.runner)
55+
androidTestImplementation(libs.truth)
6456
}
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'
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1+
<!--
2+
~ Copyright 2023 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+
~ http://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+
117
<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"/>
18+
package="com.google.firebase.crashlytics.ktx"
19+
android:versionCode="1"
20+
android:versionName="1.0.0">
21+
622
<application>
7-
<uses-library android:name="android.test.runner" />
23+
824
</application>
925

10-
<instrumentation
11-
android:name="androidx.test.runner.AndroidJUnitRunner"
12-
android:targetPackage="com.google.firebase.crashlytics.ktx" />
26+
<uses-permission android:name="android.permission.INTERNET" />
1327
</manifest>

firebase-crashlytics/ktx/src/androidTest/kotlin/com/google/firebase/crashlytics/ktx/CrashlyticsTests.kt

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,38 @@
1414

1515
package com.google.firebase.crashlytics.ktx
1616

17-
import androidx.test.InstrumentationRegistry
18-
import androidx.test.runner.AndroidJUnit4
17+
import androidx.test.core.app.ApplicationProvider
18+
import androidx.test.ext.junit.runners.AndroidJUnit4
1919
import com.google.common.truth.Truth.assertThat
2020
import com.google.firebase.FirebaseApp
21+
import com.google.firebase.FirebaseOptions
2122
import com.google.firebase.crashlytics.FirebaseCrashlytics
2223
import com.google.firebase.ktx.Firebase
2324
import com.google.firebase.ktx.app
2425
import com.google.firebase.ktx.initialize
2526
import com.google.firebase.platforminfo.UserAgentPublisher
26-
import org.junit.AfterClass
27-
import org.junit.BeforeClass
27+
import org.junit.After
28+
import org.junit.Before
2829
import org.junit.Test
2930
import org.junit.runner.RunWith
3031

3132
@RunWith(AndroidJUnit4::class)
3233
class CrashlyticsTests {
33-
companion object {
34-
lateinit var app: FirebaseApp
35-
36-
@BeforeClass
37-
@JvmStatic
38-
fun setup() {
39-
app = Firebase.initialize(InstrumentationRegistry.getContext())!!
40-
}
34+
@Before
35+
fun setUp() {
36+
Firebase.initialize(
37+
ApplicationProvider.getApplicationContext(),
38+
FirebaseOptions.Builder()
39+
.setApplicationId(APP_ID)
40+
.setApiKey(API_KEY)
41+
.setProjectId(PROJECT_ID)
42+
.build()
43+
)
44+
}
4145

42-
@AfterClass
43-
@JvmStatic
44-
fun cleanup() {
45-
app.delete()
46-
}
46+
@After
47+
fun cleanUp() {
48+
FirebaseApp.clearInstancesForTest()
4749
}
4850

4951
@Test
@@ -52,32 +54,14 @@ class CrashlyticsTests {
5254
}
5355

5456
@Test
55-
fun testDataCall() {
56-
assertThat("hola").isEqualTo("hola")
57+
fun libraryRegistrationAtRuntime() {
58+
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
59+
assertThat(publisher.userAgent).contains(FirebaseCrashlyticsKtxRegistrar.LIBRARY_NAME)
5760
}
58-
}
5961

60-
@RunWith(AndroidJUnit4::class)
61-
class LibraryVersionTest {
6262
companion object {
63-
lateinit var app: FirebaseApp
64-
65-
@BeforeClass
66-
@JvmStatic
67-
fun setup() {
68-
app = Firebase.initialize(InstrumentationRegistry.getContext())!!
69-
}
70-
71-
@AfterClass
72-
@JvmStatic
73-
fun cleanup() {
74-
app.delete()
75-
}
76-
}
77-
78-
@Test
79-
fun libraryRegistrationAtRuntime() {
80-
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
81-
assertThat(publisher.userAgent).contains(LIBRARY_NAME)
63+
private const val APP_ID = "1:1:android:1a"
64+
private const val API_KEY = "API-KEY-API-KEY-API-KEY-API-KEY-API-KEY"
65+
private const val PROJECT_ID = "PROJECT-ID"
8266
}
8367
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ fun FirebaseCrashlytics.setCustomKeys(init: KeyValueBuilder.() -> Unit) {
3232
builder.init()
3333
}
3434

35-
internal const val LIBRARY_NAME: String = "fire-cls-ktx"
36-
3735
/** @suppress */
3836
@Keep
39-
class FirebaseCrashlyticsKtxRegistrar : ComponentRegistrar {
37+
internal class FirebaseCrashlyticsKtxRegistrar : ComponentRegistrar {
4038
override fun getComponents(): List<Component<*>> =
4139
listOf(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
40+
41+
companion object {
42+
internal const val LIBRARY_NAME: String = "fire-cls-ktx"
43+
}
4244
}

health-metrics/apk-size/app/default.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ android {
2525
abortOnError false
2626
checkReleaseBuilds false
2727
}
28-
compileSdkVersion project.targetSdkVersion
28+
compileSdk 33
2929

3030
defaultConfig {
3131
applicationId 'com.google.apksize'
3232
minSdkVersion project.targetSdkVersion
3333
multiDexEnabled true
34-
targetSdkVersion project.targetSdkVersion
34+
targetSdkVersion 33
3535
versionCode 1
3636
versionName '1.0'
3737
}

0 commit comments

Comments
 (0)