From 41b6765da8fb0c05dff8b339ca23b6a3d39839d9 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 18 Apr 2021 17:58:23 -0700 Subject: Fix coroutine tests --- .../kotlin/com/pitchedapps/frost/FrostTestApp.kt | 41 ++-------------------- .../kotlin/com/pitchedapps/frost/TestModules.kt | 19 ++++++++++ 2 files changed, 21 insertions(+), 39 deletions(-) create mode 100644 app/src/androidTest/kotlin/com/pitchedapps/frost/TestModules.kt (limited to 'app/src/androidTest') diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt index 9d0caae6..2a834cc8 100644 --- a/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt @@ -19,22 +19,13 @@ package com.pitchedapps.frost import android.app.Application import android.content.Context import androidx.test.runner.AndroidJUnitRunner -import ca.allanwang.kau.kpref.KPrefFactory -import ca.allanwang.kau.kpref.KPrefFactoryInMemory -import com.pitchedapps.frost.db.FrostDatabase -import com.pitchedapps.frost.facebook.FbCookie -import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs +import dagger.hilt.android.testing.HiltTestApplication import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement -import org.koin.android.ext.koin.androidContext -import org.koin.android.ext.koin.androidLogger import org.koin.core.component.KoinComponent import org.koin.core.component.get -import org.koin.core.context.startKoin -import org.koin.core.module.Module -import org.koin.dsl.module class FrostTestRunner : AndroidJUnitRunner() { override fun newApplication( @@ -42,7 +33,7 @@ class FrostTestRunner : AndroidJUnitRunner() { className: String?, context: Context? ): Application { - return super.newApplication(cl, FrostTestApp::class.java.name, context) + return super.newApplication(cl, HiltTestApplication::class.java.name, context) } } @@ -58,31 +49,3 @@ class FrostTestRule : TestRule { } } } - -class FrostTestApp : Application() { - - override fun onCreate() { - super.onCreate() - startKoin { - androidLogger() - androidContext(this@FrostTestApp) - modules( - listOf( - FrostDatabase.module(), - prefFactoryModule(), - Prefs.module(), - FbCookie.module(), - ThemeProvider.module() - ) - ) - } - } - - companion object { - fun prefFactoryModule(): Module = module { - single { - KPrefFactoryInMemory - } - } - } -} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/TestModules.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/TestModules.kt new file mode 100644 index 00000000..3d43f1b1 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/TestModules.kt @@ -0,0 +1,19 @@ +package com.pitchedapps.frost + +import ca.allanwang.kau.kpref.KPrefFactory +import ca.allanwang.kau.kpref.KPrefFactoryInMemory +import com.pitchedapps.frost.prefs.PrefFactoryModule +import dagger.Module +import dagger.Provides +import dagger.hilt.components.SingletonComponent +import dagger.hilt.testing.TestInstallIn + +@Module +@TestInstallIn( + components = [SingletonComponent::class], + replaces = [PrefFactoryModule::class] +) +object PrefFactoryTestModule { + @Provides + fun factory(): KPrefFactory = KPrefFactoryInMemory +} -- cgit v1.2.3