Skip to content

Commit 361c007

Browse files
committed
Fixed issues for AndroidUnitTest
1 parent 76445e7 commit 361c007

File tree

47 files changed

+246
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+246
-35
lines changed

build.gradle.kts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ subprojects {
172172
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
173173
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion")
174174
"androidMainImplementation"(platform("com.google.firebase:firebase-bom:$firebaseBoMVersion"))
175-
"commonTestImplementation"(kotlin("test-common"))
176-
"commonTestImplementation"(kotlin("test-annotations-common"))
175+
"commonTestImplementation"(kotlin("test"))
177176
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
178177
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
179178
if (this@afterEvaluate.name != "firebase-crashlytics") {
@@ -187,6 +186,12 @@ subprojects {
187186
}
188187
}
189188

189+
// Workaround for setting kotlinOptions.jvmTarget
190+
// See https://youtrack.jetbrains.com/issue/KT-55947/Unable-to-set-kapt-jvm-target-version
191+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
192+
kotlinOptions.jvmTarget = "11"
193+
}
194+
190195
if (skipPublishing) return@subprojects
191196

192197
apply(plugin = "maven-publish")
@@ -245,18 +250,12 @@ subprojects {
245250
}
246251

247252
}
248-
249-
// Workaround for setting kotlinOptions.jvmTarget
250-
// See https://youtrack.jetbrains.com/issue/KT-55947/Unable-to-set-kapt-jvm-target-version
251-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
252-
kotlinOptions.jvmTarget = "11"
253-
}
254253
}
255254

256255
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
257256

258257
fun isNonStable(version: String): Boolean {
259-
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
258+
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase(java.util.Locale.ENGLISH).contains(it) }
260259
val versionMatch = "^[0-9,.v-]+(-r)?$".toRegex().matches(version)
261260

262261
return (stableKeyword || versionMatch).not()

firebase-app/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ kotlin {
102102
}
103103
}
104104

105-
val commonTest by getting
105+
val commonTest by getting {
106+
dependencies {
107+
implementation(project(":test-utils"))
108+
}
109+
}
106110

107111
getByName("androidMain") {
108112
dependencies {

firebase-app/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ import androidx.test.platform.app.InstrumentationRegistry
1010
actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext
1111

1212
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }
13+
actual annotation class IgnoreForAndroidUnitTest()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:JvmName("tests")
6+
package dev.gitlive.firebase
7+
8+
import org.junit.Ignore
9+
10+
actual val context: Any = ""
11+
12+
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }
13+
14+
// Tests are to be run on AndroidInstrumentedTests.
15+
// Kotlin 1.8 does not allow us to remove the commonTest dependency from AndroidUnitTest
16+
// Therefore we just wont run them
17+
// Kotlin 1.9 will introduce methods for disabling tests properly
18+
actual typealias IgnoreForAndroidUnitTest = Ignore

firebase-app/src/commonTest/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import kotlin.test.Test
44

55
expect val context: Any
66
expect fun runTest(test: suspend () -> Unit)
7+
expect annotation class IgnoreForAndroidUnitTest constructor()
78

9+
@IgnoreForAndroidUnitTest
810
class FirebaseAppTest {
911
@Test
1012
fun testInitialize() {

firebase-app/src/iosTest/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ actual fun runTest(test: suspend () -> Unit) = runBlocking {
2020
}
2121
testRun.await()
2222
}
23+
24+
actual annotation class IgnoreForAndroidUnitTest()

firebase-app/src/jsTest/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ actual val context: Any = Unit
1010

1111
actual fun runTest(test: suspend () -> Unit) {
1212
runTest { test() }
13-
}
13+
}
14+
15+
actual annotation class IgnoreForAndroidUnitTest()

firebase-auth/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ kotlin {
116116
}
117117
}
118118

119-
val commonTest by getting
119+
val commonTest by getting {
120+
dependencies {
121+
implementation(project(":test-utils"))
122+
}
123+
}
120124

121125
getByName("androidMain") {
122126
dependencies {

firebase-auth/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ actual val emulatorHost: String = "10.0.2.2"
1212
actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext
1313

1414
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }
15+
16+
actual annotation class IgnoreForAndroidUnitTest()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:JvmName("tests")
6+
package dev.gitlive.firebase.auth
7+
8+
import org.junit.Ignore
9+
10+
actual val emulatorHost: String = "10.0.2.2"
11+
12+
actual val context: Any = ""
13+
14+
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }
15+
16+
// Tests are to be run on AndroidInstrumentedTests.
17+
// Kotlin 1.8 does not allow us to remove the commonTest dependency from AndroidUnitTest
18+
// Therefore we just wont run them
19+
// Kotlin 1.9 will introduce methods for disabling tests properly
20+
actual typealias IgnoreForAndroidUnitTest = Ignore

0 commit comments

Comments
 (0)