Android Instrumentation测试:未注册任何仪器错误

kcc*_*c__ 2 java android android-studio android-espresso

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

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

我无法理解此错误的含义。

我将简要解释我在测试中正在做的事情。我跟着样品由谷歌并给予EspressoTesting教程

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

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


   @Before
   public void setUp(){}
}
Run Code Online (Sandbox Code Playgroud)

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

aud*_*ans 8

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

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'
Run Code Online (Sandbox Code Playgroud)

最好使用com.android.support.test,而不是使用androidx库,因为如果我们一起使用它们,它们将彼此冲突。希望这可以帮助您解决错误No instrumentation registered! Must run under a registering instrumentation.

  • 这不是解决方案。它只是通过移除此异常`Androidx`测试流程的实际生成器来摆脱此异常。我需要使用Test Orchestrator进行意式咖啡测试,不能使用常规的`com.android.support.test:runner:1.0.2` (2认同)