Android Studio 单元测试:无法找到检测或类未找到前 [英] Android Studio Unit Testing: unable to find instrumentation OR class not found ex

查看:94
本文介绍了Android Studio 单元测试:无法找到检测或类未找到前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android 工作室中有一个测试套件,其目录结构如下:

I have a test suite within my Android studio that has the following dir structure:

-MainProject
 -src
  --com
  --tests
    --java.xx.xxx.xx.test

在我的 AndroidManifest 中,我有以下内容:

Within my AndroidManifest, I have the following:

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="tests.java.xxx.xxx.xxx.test" />

当我从命令行使用:./gradlew connectedInstrumentTest 运行我的测试时,我只是得到:

When I run my tests from the command line using: ./gradlew connectedInstrumentTest, I simply get:

Tests on Nexus 5 - 4.4.2 failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'

当我从 Android Studio 内部运行测试时,我得到:

When I run the tests from inside Android Studio I get:

Running tests
Test running startedTest running failed: Unable to find instrumentation info for: ComponentInfo{tests.xxx.xxx.xxx.xxx.test/android.test.InstrumentationTestRunner}
Empty test suite.

我还在 build.gradle 文件的 defaultConfig 中指定了 testPackageName.我在 Ubuntu 12.0.4 上运行 Android Studio 0.4.6.

I also have the testPackageName specified in my defaultConfig in the build.gradle file. Am running Android Studio 0.4.6 on Ubuntu 12.0.4.

有什么想法吗?

推荐答案

我遇到了同样的问题,在网上找不到任何东西.答案非常简单:您必须编辑测试的 RunConfiguration,使其不是 Android 测试而是 JUnit 测试.

I had the same problem and could not find anything on the net. The answer was pretty simple: You have to edit the RunConfiguration of your test so that it is not a Android Test but a JUnit test.

所以基本上我做了以下事情:

So basically I did the following:

  1. 点击编辑配置"
  2. 点击添加新配置"并选择 JUnit
  3. 在测试种类中插入了名称和并选择了All in package".

就是这样.

这篇关于Android Studio 单元测试:无法找到检测或类未找到前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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