Skip to content

Commit

Permalink
Increase runAppTest timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed May 16, 2023
1 parent e5e8491 commit a137212
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.alexvanyo.composelife.test
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.alexvanyo.composelife.updatable.Updatable
import dagger.hilt.android.testing.HiltAndroidRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.TestScope
Expand All @@ -30,14 +29,15 @@ import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.BeforeTest
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

/**
* A base class for testing components that depend on Hilt injected classes.
*
* Subclasses must call [runAppTest] instead of [runTest] to properly initialize dependencies.
*/
@Suppress("UnnecessaryAbstractClass")
@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(AndroidJUnit4::class)
abstract class BaseHiltTest {

Expand All @@ -54,8 +54,12 @@ abstract class BaseHiltTest {

fun runAppTest(
context: CoroutineContext = EmptyCoroutineContext,
timeout: Duration = 60.seconds,
testBody: suspend TestScope.() -> Unit,
): TestResult = runTest(context) {
): TestResult = runTest(
context = context,
timeout = timeout,
) {
updatables.forEach { updatable ->
backgroundScope.launch {
updatable.update()
Expand Down

0 comments on commit a137212

Please sign in to comment.