[Android] Add InstantTaskExecutorRule to androidTest

Habib Kazemi git at videolan.org
Mon Feb 11 13:25:27 CET 2019


vlc-android | branch: master | Habib Kazemi <kazemihabib1996 at gmail.com> | Mon Feb 11 13:30:56 2019 +0330| [225fffa6c67029f5e7f024980d80af76ea3c35a4] | committer: Geoffrey Métais

Add InstantTaskExecutorRule to androidTest

without that the getValue() throws "java.lang.IllegalStateException: Cannot
invoke observeForever on a background thread"

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/225fffa6c67029f5e7f024980d80af76ea3c35a4
---

 vlc-android/androidTest/org/videolan/vlc/database/DbTest.kt        | 4 ++++
 vlc-android/androidTest/org/videolan/vlc/database/MigrationTest.kt | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/vlc-android/androidTest/org/videolan/vlc/database/DbTest.kt b/vlc-android/androidTest/org/videolan/vlc/database/DbTest.kt
index 04eef9bb7..a4f1d7c74 100644
--- a/vlc-android/androidTest/org/videolan/vlc/database/DbTest.kt
+++ b/vlc-android/androidTest/org/videolan/vlc/database/DbTest.kt
@@ -21,6 +21,7 @@
 package org.videolan.vlc.database
 
 import androidx.arch.core.executor.testing.CountingTaskExecutorRule
+import androidx.arch.core.executor.testing.InstantTaskExecutorRule
 import androidx.room.Room
 import androidx.test.InstrumentationRegistry
 import org.junit.After
@@ -30,6 +31,9 @@ import java.util.concurrent.TimeUnit
 
 
 abstract class DbTest {
+    @get:Rule
+    var instantTaskExecutorRule = InstantTaskExecutorRule()
+
     @Rule
     @JvmField
     val countingTaskExecutorRule = CountingTaskExecutorRule()
diff --git a/vlc-android/androidTest/org/videolan/vlc/database/MigrationTest.kt b/vlc-android/androidTest/org/videolan/vlc/database/MigrationTest.kt
index f9a6bda5a..f7c79c83e 100644
--- a/vlc-android/androidTest/org/videolan/vlc/database/MigrationTest.kt
+++ b/vlc-android/androidTest/org/videolan/vlc/database/MigrationTest.kt
@@ -25,6 +25,7 @@ import androidx.room.Room
 import androidx.room.migration.Migration
 import androidx.room.testing.MigrationTestHelper
 import android.net.Uri
+import androidx.arch.core.executor.testing.InstantTaskExecutorRule
 import androidx.test.InstrumentationRegistry
 import androidx.test.runner.AndroidJUnit4
 import org.hamcrest.CoreMatchers.`is`
@@ -48,6 +49,9 @@ private const val TEST_DB_NAME = "test-db"
 
 @RunWith(AndroidJUnit4::class)
 class MigrationTest {
+    @get:Rule
+    var instantTaskExecutorRule = InstantTaskExecutorRule()
+
     @get:Rule
     val migrationTestHelper = MigrationTestHelper(
             InstrumentationRegistry.getInstrumentation(),



More information about the Android mailing list