Skip to content

Commit

Permalink
Initialize WorkManager for instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed Feb 23, 2024
1 parent 014b358 commit e8c900e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ dependencies {
androidTestImplementation("androidx.test:rules:1.4.0")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("io.mockk:mockk-android:1.13.8")
androidTestImplementation("androidx.work:work-testing:2.9.0-alpha01")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stevesoltys.seedvault

import android.os.Build.VERSION.SDK_INT
import android.util.Log
import com.stevesoltys.seedvault.restore.RestoreViewModel
import com.stevesoltys.seedvault.settings.SettingsManager
import com.stevesoltys.seedvault.transport.backup.FullBackup
Expand Down Expand Up @@ -65,5 +66,8 @@ class KoinInstrumentationTestApp : App() {
override fun migrateToOwnScheduling() {
// IBackupManager#setFrameworkSchedulingEnabledForUser() not available on 33 and below
if (SDK_INT >= 34) super.migrateToOwnScheduling()
else {
Log.w("App", "Not running scheduling migration due to old version.")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.stevesoltys.seedvault.e2e

import android.content.pm.PackageManager
import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.work.Configuration
import androidx.work.impl.utils.SynchronousExecutor
import androidx.work.testing.WorkManagerTestInitHelper
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
Expand Down Expand Up @@ -36,6 +40,13 @@ internal abstract class SeedvaultLargeTest :

@Before
open fun setUp() = runBlocking {
// Initialize WorkManager for instrumentation tests
val config = Configuration.Builder()
.setMinimumLoggingLevel(Log.DEBUG)
.setExecutor(SynchronousExecutor())
.build()
WorkManagerTestInitHelper.initializeTestWorkManager(targetContext, config)

resetApplicationState()
clearTestBackups()

Expand Down

0 comments on commit e8c900e

Please sign in to comment.