Skip to content

Commit

Permalink
Enforce tests to start with clean Firebase app
Browse files Browse the repository at this point in the history
This hopefully makes tests more stable (and more accurate
  • Loading branch information
Daeda88 committed Sep 27, 2023
1 parent d58c6b5 commit 4caba6b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.gitlive.firebase

import kotlin.test.Test
import kotlin.test.assertEquals

expect val context: Any
expect fun runTest(test: suspend () -> Unit)
Expand All @@ -21,6 +22,12 @@ class FirebaseAppTest {
gcmSenderId = "846484016111"
)
)

assertEquals(1, Firebase.apps(context).size)

Firebase.apps(context).forEach {
it.delete()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class FirebaseAuthTest {
}
}

@AfterTest
fun deinitializeFirebase() {
Firebase.apps(context).forEach {
it.delete()
}
}

@Test
fun testSignInWithUsernameAndPassword() = runTest {
val uid = getTestUid("[email protected]", "test123")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class FirebaseRemoteConfigTest {
@AfterTest
fun tearDown() = runTest {
Firebase.remoteConfig.reset()
Firebase.apps(context).forEach {
it.delete()
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.gitlive.firebase.apps
import dev.gitlive.firebase.initialize
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.test.TestResult
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertFalse
Expand Down Expand Up @@ -41,6 +42,13 @@ class FirebaseCrashlyticsTest {
}
}

@AfterTest
fun deinitializeFirebase() {
Firebase.apps(context).forEach {
it.delete()
}
}

@Test
fun testRecordException() = runTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class FirebaseDatabaseTest {
}
}

@AfterTest
fun deinitializeFirebase() {
Firebase.apps(context).forEach {
it.delete()
}
}

@Test
fun testSetValue() = runTest {
val testValue = "test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.nullable
import kotlin.random.Random
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -69,6 +70,13 @@ class FirebaseFirestoreTest {
}
}

@AfterTest
fun deinitializeFirebase() {
Firebase.apps(context).forEach {
it.delete()
}
}

@Test
fun testStringOrderBy() = runTest {
setupFirestoreData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class FirebasePerformanceTest {
}
}

@AfterTest
fun deinitializeFirebase() {
Firebase.apps(context).forEach {
it.delete()
}
}

@Test
fun testNewTrace() = runTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ actual val emulatorHost: String = "localhost"

actual val context: Any = Unit

actual fun runTest(test: suspend CoroutineScope.() -> Unit) = kotlinx.coroutines.test.runTest(timeout = 5.minutes) { test() }
actual fun runTest(test: suspend CoroutineScope.() -> Unit) = kotlinx.coroutines.test.runTest(timeout = 5.minutes) {
test()
}

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
Expand Down

0 comments on commit 4caba6b

Please sign in to comment.