未注册仪器!必须在注册工具下运行



我在运行我的浓缩咖啡测试时得到以下错误:

java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.
at androidx.test.platform.app.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:45)
at androidx.test.espresso.base.BaseLayerModule.provideTargetContext(BaseLayerModule.java:1)
at androidx.test.espresso.base.BaseLayerModule_ProvideTargetContextFactory.provideTargetContext(BaseLayerModule_ProvideTargetContextFactory.java:1)
at androidx.test.espresso.base.BaseLayerModule_ProvideTargetContextFactory.get(BaseLayerModule_ProvideTargetContextFactory.java:1)
at androidx.test.espresso.base.BaseLayerModule_ProvideTargetContextFactory.get(BaseLayerModule_ProvideTargetContextFactory.java:2)
at androidx.test.espresso.base.BaseLayerModule_ProvideDefaultFailureHanderFactory.get(BaseLayerModule_ProvideDefaultFailureHanderFactory.java:1)
at androidx.test.espresso.base.BaseLayerModule_ProvideDefaultFailureHanderFactory.get(BaseLayerModule_ProvideDefaultFailureHanderFactory.java:2)
at androidx.test.espresso.base.BaseLayerModule_ProvideFailureHanderFactory.get(BaseLayerModule_ProvideFailureHanderFactory.java:1)
at androidx.test.espresso.base.BaseLayerModule_ProvideFailureHanderFactory.get(BaseLayerModule_ProvideFailureHanderFactory.java:2)
at androidx.test.espresso.base.BaseLayerModule_FailureHandlerHolder_Factory.get(BaseLayerModule_FailureHandlerHolder_Factory.java:1)
at androidx.test.espresso.base.BaseLayerModule_FailureHandlerHolder_Factory.get(BaseLayerModule_FailureHandlerHolder_Factory.java:2)
at androidx.test.espresso.core.internal.deps.dagger.internal.DoubleCheck.get(DoubleCheck.java:6)
at androidx.test.espresso.DaggerBaseLayerComponent.failureHandler(DaggerBaseLayerComponent.java:1)
at androidx.test.espresso.DaggerBaseLayerComponent$ViewInteractionComponentImpl.viewInteraction(DaggerBaseLayerComponent.java:1)
at androidx.test.espresso.Espresso.onView(Espresso.java:1)
at com.example.espressotest.FirstTest.test1ChatId(FirstTest.java:51)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2189)

我在build.gradle

中添加了以下依赖项
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
testImplementation 'org.robolectric:robolectric:4.0.2'
testImplementation 'androidx.test:core-ktx:1.3.0'
testImplementation 'androidx.test.ext:junit-ktx:1.1.2'
androidTestCompile 'com.android.support:support-annotations:24.0.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestImplementation "com.android.support:support-annotations:27.1.1"
androidTestImplementation 'com.android.support.test:rules:1.0.2'
android {
defaultConfig {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
testOptions {
unitTests.includeAndroidResources = true
}
}
}

我试着遵循这里提到的解决方案AndroidX:没有仪器注册!必须在注册工具下运行,但它不适合我。

有人能帮我解决吗?

你需要修复你的依赖

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

应该

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

最新更新