尝试使用multidex应用程序运行espresso 2.0时遇到了实际问题,我继续进行消息测试,然后退出并说空测试套件
Success
Running testsTesting started at 08:56 ...
Connected to the target VM, address: 'localhost:8601', transport: 'socket'
Test running startedFinish
Disconnected from the target VM, address: 'localhost:8601', transport: 'socket'
Empty test suite.
这是我的项目组织
我的测试用例
@LargeTest
public class MainActivityInstrumentTest
extends ActivityInstrumentationTestCase2<MainActivity> {
private MainActivity mActivity;
public MainActivityInstrumentTest() {
super(MainActivity.class);
}
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
@SmallTest
public void checkPreconditions() {
assertThat(mActivity, notNullValue());
assertThat(getInstrumentation(), notNullValue());
onView(withId(R.id.txtUsername))
.perform(typeText("Steve"));
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
allprojects {
repositories {
mavenCentral()
}
}
这是我的gradle构建脚本
apply plugin: 'com.android.application'
repositories {
maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
mavenCentral()
jcenter()
maven {
url 'https://repo.commonsware.com.s3.amazonaws.com'
}
}
android {
ext {
compileSdkVersion = compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion = buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
minSdkVersion = Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion = Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
versionCode 18
versionName 'beta version 7'
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
applicationId 'com.closr.closr'
//testPackageName "androidTest.java.com.closr.closr"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testFunctionalTest true
testApplicationId "com.closr.closr.test"
//testInstrumentationRunner "android.support.multidex.MultiDexTestRunner"
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'src/main/java', 'src/androidTest/java/', 'src/androidTest', 'src/androidTest/java']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// androidTest {
// setRoot('androidTest')
// java.srcDirs = ['androidTest/java']
// }
dexOptions {
incremental false
preDexLibraries = false
jumboMode = false
javaMaxHeapSize "2g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'LICENSE.txt'
}
lintOptions {
abortOnError false
}
}
signingConfigs {
debug {
storeFile file('xxxxxxxxxxxxxxxxxxxxxxxxxxx')
storePassword 'xxxxxxxxxxx'
keyAlias 'xxxxxxxxxxxxxxxxxx'
keyPassword 'xxxxxxxxxxxxxxxxxx'
}
release {
storeFile file('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
storePassword 'xxxxxx'
keyAlias 'xxxxxxxx'
keyPassword 'xxxxxxxxx'
}
}
buildTypes {
debug {
minifyEnabled false
// proguardFile 'proguard.cfg'
// signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFile 'proguard.cfg'
signingConfig signingConfigs.release
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
project.tasks.withType(JavaCompile) { task ->
options.compilerArgs << "- AguiceAnnotationDatabasePackageName=com.closr.closr"
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
afterEvaluate {
// tasks.findByName("assembleDebug").dependsOn("testDebugClasses")
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
}
dependencies {
compile 'com.android.support:support-annotations:21.0.3'
compile 'com.android.support:multidex:1.0.0'
///compile 'com.google.android:multidex:0.1'
compile files('libs/aws-android-sdk-1.7.1.1.jar')
//compile 'com.amazonaws:aws-java-sdk:1.9.3'
compile 'com.makeramen:roundedimageview:1.3.0'
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
compile 'com.squareup.picasso:picasso:2.3.3'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'com.google.android.gms:play-services:+'
compile 'com.androidmapsextensions:android-maps-extensions:2.1.+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:21.+'
//compile 'com.android.support:appcompat-v7:21.+'
compile 'com.jeremyfeinstein.slidingmenu:library:1.3@aar'
compile('com.commonsware.cwac:camera-v9:0.6.+') {
exclude module: 'support-v4'
}
compile 'com.squareup:otto:1.3.6'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okio:okio:1.2.0'
compile project(':libraries:facebook')
compile files('libs/Catalano.Core.jar')
compile files('libs/Catalano.Android.Image.jar')
compile files('libs/Catalano.Math.jar')
//compile 'junit:junit:4.12'
compile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
exclude module: 'commons-codec'
}
compile 'junit:junit:4.12'
compile('org.roboguice:roboguice:3.+') {
exclude group: 'javax.inject'
exclude group: 'org.hamcrest'
exclude group: 'junit'
}
provided 'org.roboguice:roboblender:3.+'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile ('com.android.support.test.espresso:espresso-core:2.0') {
exclude group: 'javax.inject'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'org.hamcrest'
exclude group: 'junit'
}
compile ('com.android.support.test:testing-support-lib:0.1'){
exclude group: 'junit'
}
compile ('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude group: 'javax.inject'
exclude group: 'com.android.support'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
exclude group: 'org.hamcrest'
exclude group: 'junit'
}
// compile ('com.android.support:multidex-instrumentation:1.0.0'){
// exclude module: 'multidex'
// }
}
Log cat中的错误
03-12 09:02:47.064 4192-4192/com.closr.closr E/dalvikvm﹕ Could not find class 'org.junit.internal.TextListener', referenced from method android.support.test.runner.AndroidJUnitRunner.addListeners
03-12 09:02:47.064 4192-4192/com.closr.closr E/dalvikvm﹕ Could not find class 'org.junit.runner.JUnitCore', referenced from method android.support.test.runner.AndroidJUnitRunner.onStart
答案 0 :(得分:3)
要测试支持multidex的应用,您需要使用其他testInstrumentationRunner
android {
defaultConfig {
...
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
}
如果Gradle版本的Android插件低于1.1,则需要添加以下依赖项:
dependencies {
androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex'
}
}
更多信息:
https://developer.android.com/tools/building/multidex.html#testing
答案 1 :(得分:1)
将测试文件夹从instrumentTest
重命名为androidTest
。