测试运行失败:无法找到检测信息:ComponentInfo {} - 尝试在IntelliJ中使用Gradle进行测试时发生错误 [英] Test running failed: Unable to find instrumentation info for: ComponentInfo{} -- error trying to test in IntelliJ with Gradle

查看:184
本文介绍了测试运行失败:无法找到检测信息:ComponentInfo {} - 尝试在IntelliJ中使用Gradle进行测试时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 运行测试
测试运行开始测试运行失败每次我尝试运行测试时,控制台都会这样说: :无法找到工具信息:
ComponentInfo {com.employeeappv2.employeeappv2.test / android.test.InstrumentationTestRunner}
空测试套件。

我一直坚持这一段时间,至今我在网上看到的解决方案都有没有帮助。
我的项目结构是这样设置的:

*主模块
-src
* instrumentTest
-java
* main
-java
-manifest
* build.gradle


我的build.gradle文件如下所示:

  buildscript {
储存库{
mavenCentral()
}
依赖项{
classpath'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin:'android'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion19.1.0

defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName2.1.0
testPackageNamelogin.test
testInstrumentationRunnerandroid.test.InstrumentationTestRunner
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.tx t'),'proguard-rules.txt'
}
}

packagingOptions {
排除'META-INF / LICENSE'
排除'META -INF / NOTICE'
排除'META-INF / notice.txt'
排除'META-INF / license.txt'
}
}

依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
编译文件('libs / scandit.zip')
compile project(': pullToRefresh')
compile'c​​om.android.support:appcompat-v7:19.+'
compile'c​​om.nostra13.universalimageloader:universal-image-loader:1.9.1+'
编译'org.springframework.android:spring-android-rest-template:1.0.1+'
compile'org.json:json:20090211'
compile'c​​om.fasterxml.jackson.core:jackson -databind:2.3.1'
compile'c​​om.fasterxml.jackson.core:jackson-annotations:2.3.0'
compile'c​​om.fasterxml.jackson.core:jackson-core:2.3.1 '
compile'c​​om.android.support:support-v4:19.1.+'
compile'c​​om.mcxiaoke.volle y:library:1.0。+ @ aar'
androidTestCompile'junit:junit:3.8'
}

您是否需要为您的测试目录提供单独的清单?如果是这样会是什么样子?



编辑:我试着添加一个清单到我的instrumentTest目录中,但没有运气。请注意,我无法使用IntelliJ来解析targetPackage名称,因此它显示为红色。

 < manifest xmlns:android = http://schemas.android.com/apk/res/android
package =com.employeeappv2.employeeappv2.src.instrumentTest
android:versionCode =1
android:的versionName = 1.0.0 >
< application>
< uses-library android:name =android.test.runner/>
< / application>
< instrumentation
android:name =android.test.InstrumentationTestRunner
android:targetPackage =com.employeeappv2.employeeappv2.src.main/>
< / manifest>


解决方案

所以主要问题是当我创建一个androidTest文件夹在/ src /下,它没有被IntelliJ拾取为测试的源文件夹(java子目录应该变成绿色)。我使用的IntelliJ 13.0.3和升级到13.1.3后,我所有的麻烦都消失了。注意:不要尝试向你的androidTest文件夹添加一个清单,Gradle文档特别指出当你创建androidTest文件夹时应该自动生成清单。对我来说问题在于该文件没有被生成,因为androidTest没有被IntelliJ / Gradle识别,因此抛出了没有检测错误。


Everytime I try to run my tests the console says this:

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

I've been stuck on this for a while and the solutions I've seen online so far have not helped. My project structure is set up like this:

*Main Module -src *instrumentTest -java *main -java -manifest *build.gradle

My build.gradle file looks like this:

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.1.0"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 19
    versionCode 1
    versionName "2.1.0"
    testPackageName "login.test"
    testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-   rules.txt'
    }
}

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/scandit.zip')
compile project(':pullToRefresh')
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.1+'
compile 'org.springframework.android:spring-android-rest-template:1.0.1+'
compile 'org.json:json:20090211'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.3.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.3.1'
compile 'com.android.support:support-v4:19.1.+'
compile 'com.mcxiaoke.volley:library:1.0.+@aar'
androidTestCompile 'junit:junit:3.8'
}

Do you need to have a separate manifest for your tests directory? If so what would that look like?

Edit: I tried adding a manifest to my instrumentTest directory with no luck. Note that I could not get IntelliJ to resolve the targetPackage name, so it appears red.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.employeeappv2.employeeappv2.src.instrumentTest"
      android:versionCode="1"
      android:versionName="1.0.0">
<application>
    <uses-library android:name="android.test.runner" />
</application>
<instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.employeeappv2.employeeappv2.src.main"/>
</manifest>

解决方案

So the main problem was that when I created an androidTest folder under /src/, it wasn't being picked up by IntelliJ as a source folder for testing (java subdirectory should turn green). I was using IntelliJ 13.0.3 and after upgrading to 13.1.3, all of my troubles went away.

*Note: do not try to add a manifest to your androidTest folder, the Gradle docs specifically state that the manifest should be auto-generated when you create the androidTest folder. The problem for me was that the file wasn't being generated as androidTest wasn't being recognized by IntelliJ/Gradle, thus throwing the no instrumentation error.

这篇关于测试运行失败:无法找到检测信息:ComponentInfo {} - 尝试在IntelliJ中使用Gradle进行测试时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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