From 2c5989919c534626252821e71419cdd07b12e84e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Mar 2023 16:20:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + .../io/legado/app/ExampleInstrumentedTest.kt | 22 +++++++++++++------ .../java/io/legado/app/MigrationTest.kt | 3 ++- rhino/build.gradle | 1 - 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6c25552bf..09fdbc638 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -139,6 +139,7 @@ dependencies { //coreLibraryDesugaring('com.android.tools:desugar_jdk_libs_nio:2.0.2') testImplementation('junit:junit:4.13.2') androidTestImplementation('androidx.test:runner:1.5.2') + androidTestImplementation('androidx.test.ext:junit:1.1.3') androidTestImplementation('androidx.test.espresso:espresso-core:3.5.1') //kotlin //noinspection GradleDependency,DifferentStdlibGradleVersion diff --git a/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt b/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt index 4059bc269..56130db62 100644 --- a/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt @@ -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() + Log.d( + "test", + appContext.contentResolver.query( + Uri.parse("content://io.legado.app.api.ReaderProvider/sources/query"), + null, + null, + null, + null + ) + !!.getString(0) ) - } + } } diff --git a/app/src/androidTest/java/io/legado/app/MigrationTest.kt b/app/src/androidTest/java/io/legado/app/MigrationTest.kt index 64b7c5f17..3bf1c00c9 100644 --- a/app/src/androidTest/java/io/legado/app/MigrationTest.kt +++ b/app/src/androidTest/java/io/legado/app/MigrationTest.kt @@ -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( diff --git a/rhino/build.gradle b/rhino/build.gradle index 2a25cc693..cbaf2121f 100644 --- a/rhino/build.gradle +++ b/rhino/build.gradle @@ -11,7 +11,6 @@ android { minSdk 21 targetSdk 33 - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" }