Android Instrumentation测试:未注册任何仪器错误 [英] Android Instrumentation Testing: No instrumentation registered Error

查看:327
本文介绍了Android Instrumentation测试:未注册任何仪器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Espresso编写Android Instrumented测试.当我运行测试时,出现此错误

I am trying to write Android Instrumented test using Espresso. When I run the test I get this error

java.lang.IllegalStateException:未注册任何工具!必须在注册工具下运行.

java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.

我不明白此错误的含义.

I can't understand what this error means.

我将简要解释我在测试中正在做的事情.我遵循了google和示例/LearnShareKnowledge/EspressoTestingUi"rel =" nofollow noreferrer> EspressoTesting教程

I will briefly explain what I am doing in my test. I followed the samples given by google and EspressoTesting Tutorial

@SmallTest
@RunWith(AndroidJUnit4.class)
public class ActivityInputTest {

   @Rule
   public ActivityTestRule<ActivityInput> aiRule = new ActivityTestRule<>(ActivityInput.class);


   @Before
   public void setUp(){}
}

运行测试时,错误发生在注释@Rule处.我可以得到一些解释为什么会发生这种情况,或者是什么背后的问题吗?我对工作代码不感兴趣,但对问题背后的实际问题更感兴趣.

When I run the test the error occurs at annotation @Rule. Can I get some explanation why this happens or what is the issue behind this? I am not interested in working code but more on the actual problem behind the issue.

推荐答案

我也遇到了与您完全相同的错误,因为我使用了androidx库.我建议您检查build.gradle中的库,并更改UI测试的依赖项,如下所示:

I also experienced error exactly same with you, because I used androidx library. I suggest you to check your libraries in build.gradle and change your dependencies for UI test like these block codes:

androidTestImplementation "com.android.support.test:runner:1.0.2"
androidTestImplementation "com.android.support.test:rules:1.0.2"
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

使用com.android.support.testandroidx库选择它们之一,因为如果我们一起使用它们,它们将彼此冲突.希望这可以帮助您解决错误No instrumentation registered! Must run under a registering instrumentation.

Choose one of them, using com.android.support.test, or androidx library, because if we use them together, they will conflict each other. Hope this can help you to resolve error No instrumentation registered! Must run under a registering instrumentation.

这篇关于Android Instrumentation测试:未注册任何仪器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆