Nic*_*oma 52 android gradle android-testing
每当我尝试运行测试时,控制台都说:
Running tests
Test running startedTest running failed: Unable to find instrumentation info for:
ComponentInfo{com.employeeappv2.employeeappv2.test/android.test.InstrumentationTestRunner}
Empty test suite.
Run Code Online (Sandbox Code Playgroud)
我已经坚持了一段时间,到目前为止我在网上看到的解决方案没有帮助.我的项目结构设置如下:
*主模块-src*instrumentTest -java*main -java -manifest*build.gradle
我的build.gradle文件如下所示:
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'
}
Run Code Online (Sandbox Code Playgroud)
您是否需要为测试目录提供单独的清单?如果是这样的话会是什么样子?
编辑:我尝试将一个清单添加到我的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>
Run Code Online (Sandbox Code Playgroud)
Pet*_*erg 27
我有同样的错误,当我尝试添加multiDexEnabled true到build.gradle.
我在这里添加了我的经验,因为这是使用... Unable to find ... ComponentInfo ...错误消息进行搜索时首批Google点击之一.
在我的情况下testInstrumentationRunner像这里添加诀窍:
...
android {
...
defaultConfig {
...
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
}
Run Code Online (Sandbox Code Playgroud)
(我有com.android.tools.build:gradle:1.5.0)
Liu*_*ing 25
我正在使用Android Studio 1.1,以下步骤为我解决了这个问题:
在Run - Edit Configurations - Android Tests
指定检测运行器中android.test.InstrumentationTestRunner
然后在"构建变体"工具窗口(左侧)中,将测试工件更改为Android Instrumentation Tests.
build.gradle中不需要testInstrumentationRunner,清单文件中不需要检测标记.
Vik*_*len 19
当我创建一个新包时,Studio创建了一个ApplicationTest类.以us.myname.mypackage为例,创建了以下目录结构:
app/[myPackage]/src/androidTest/java/us/myname/mypackage/ApplicationTest.class
Run Code Online (Sandbox Code Playgroud)
最初它开箱即用.我安装产品口味后就退出了工作.我随后对build.gradle进行了以下更改:
defaultConfig {
...
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
Run Code Online (Sandbox Code Playgroud)
有些人更喜欢
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
(使用我当前的配置,我必须...InstrumentationTestRunner在调试AndroidJUnitRunner时使用,并使用发布版本类型.)
以上配置仅适用于调试版本类型.如果您希望将它与发行版或自定义构建类型一起使用,则可以在build.gradle中包含以下内容:
buildTypes {
release {
...
}
debug {
...
}
}
testBuildType "release"
Run Code Online (Sandbox Code Playgroud)
在Studio左下角的"构建变体"选项卡中,确保选择Android Instrumentation Tests了正确的buildType选项.
LEO*_*LEO 11
对于它的价值,当我使用常规测试运行器创建自定义测试运行器后,AS 2.3被挂断了.我得到了与问题中发布的相同的错误.
删除所有 Android Instrumented测试的调试配置并重建修复它.我相信问题在于你不再可以在Debug Configurations中选择自定义跑步者,因为它很可能是通过gradle构建的.
我不得不这样做VikingGlen的组合回答,流亭的答案,而这个答案.此答案适用于Android Studio 2.1版.
运行 - >编辑配置... - >常规 - >特定检测运行器(可选):"android.support.test.runner.AndroidJUnitRunner"
在build.gradle(包含所有依赖项的那个)中,放下:
defaultConfig {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
然后它可以运行这种类型的测试:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ApplicationTest {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void login() {
//Open Drawer to click on navigation.
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed.
.perform(open()); // Open Drawer
}
}
Run Code Online (Sandbox Code Playgroud)
所以主要问题是,当我在 /src/ 下创建 androidTest 文件夹时,IntelliJ 没有将它选为测试源文件夹(java 子目录应该变成绿色)。我使用的是 IntelliJ 13.0.3,升级到 13.1.3 后,所有问题都消失了。
*注意:不要尝试将清单添加到 androidTest 文件夹中,Gradle 文档明确指出,在创建 androidTest 文件夹时应自动生成清单。对我来说,问题是该文件没有被生成,因为 androidTest 没有被 IntelliJ/Gradle 识别,从而抛出 no Instrumentation 错误。
| 归档时间: |
|
| 查看次数: |
40408 次 |
| 最近记录: |