This commit is contained in:
kunfei
2023-03-25 16:20:41 +08:00
parent 7fa0275b16
commit 753370e4a2
4 changed files with 18 additions and 9 deletions
@@ -1,9 +1,10 @@
package io.legado.app
import android.content.Context
import android.net.Uri
import android.util.Log
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
@@ -17,10 +18,17 @@ class ExampleInstrumentedTest {
@Test
fun testContentProvider() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
Log.d("test",
appContext.contentResolver.query(Uri.parse("content://io.legado.app.api.ReaderProvider/sources/query"),null,null,null,null)
!!.getString(0)
val appContext = ApplicationProvider.getApplicationContext<Context>()
Log.d(
"test",
appContext.contentResolver.query(
Uri.parse("content://io.legado.app.api.ReaderProvider/sources/query"),
null,
null,
null,
null
)
!!.getString(0)
)
}
}
}
@@ -4,8 +4,8 @@ import androidx.room.Room
import androidx.room.migration.Migration
import androidx.room.testing.MigrationTestHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import io.legado.app.data.AppDatabase
import org.junit.Rule
import org.junit.Test
@@ -14,6 +14,7 @@ import java.io.IOException
@RunWith(AndroidJUnit4::class)
class MigrationTest {
private val TEST_DB = "migration-test"
private val ALL_MIGRATIONS = arrayOf<Migration>(