为什么我没有找到测试?

时间:2014-11-13 11:57:07

标签: android android-activity android-testing android-espresso

使用以下配置执行./gradlew clean connectedAndroidTest时......我收到No tests found

这是我的build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.14.1'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.0.1'
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
    }
}

apply plugin: 'com.android.application'

android {
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LGP2.1'
        exclude 'META-INF/LGPL2.1'
    }
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    lintOptions {
        abortOnError false
    }
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 2
        versionName "0.1"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

    buildTypes {
        release {
            runProguard false
        }
    }

    sourceSets {
        androidTest {
            setRoot('src/espressoTest')
        }
    }
}

apply plugin: 'android-unit-test'

dependencies {
    // App
    compile 'com.android.support:support-v4:21.0.0'
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.android.support:gridlayout-v7:18.0.0'
    compile 'joda-time:joda-time:2.3'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'de.greenrobot:eventbus:2.0.2'
    compile 'com.squareup.dagger:dagger:1.1.0'
    compile 'com.squareup.dagger:dagger-compiler:1.1.0'
    compile 'com.google.android.gms:play-services:6.1.71'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.squareup.retrofit:retrofit:1.6.1'
    compile 'com.squareup.picasso:picasso:2.3.4'
    compile 'com.squareup:otto:1.3.5'
    compile 'com.google.guava:guava:18.0'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.wrapp.floatlabelededittext:library:0.0.3'
    compile 'com.daimajia.swipelayout:library:1.0.7@aar'
    compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
    compile 'info.hoang8f:android-segmented:1.0.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.easing:library:1.0.0@aar'
    compile 'com.daimajia.androidanimations:library:1.1.2@aar'
    compile 'com.balysv.materialmenu:material-menu-toolbar:1.4.0'

    // Espresso
    androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
    androidTestCompile 'com.google.guava:guava:14.0.1'
    androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
    androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.1'

    // Robolectric
    testCompile('junit:junit:4.11') {
        exclude module: 'hamcrest-core'
    }
    testCompile files('lib/robolectric-2.4-SNAPSHOT-jar-with-dependencies.jar')
    testCompile 'org.mockito:mockito-all:1.9.5'
    testCompile 'com.squareup:fest-android:1.0.+'
    testCompile 'com.googlecode.catch-exception:catch-exception:1.2.0'
}

tasks.findByName("assembleDebug").dependsOn("testDebugClasses")

这是src / espressoTest下的测试类:

package com.example;

import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;

import com.betavalue.myvalue.MainActivity;
import com.betavalue.myvalue.R;

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;

@LargeTest
public class MainEspressoTest extends ActivityInstrumentationTestCase2<MainActivity> {

    @SuppressWarnings("deprecation")
     public MainEspressoTest() {
       // This constructor was deprecated - but we want to support lower API levels.
       super(MainActivity.class);
     }
    @Override
    public void setUp() throws Exception {
        super.setUp();
        // Espresso will not launch our activity for us, we must launch it via getActivity().
        getActivity();
    }

    public void testCheckText() {
        onView(withId(R.id.text))
            .check(matches(withText("Hello Espresso!")));
      }
}

MainActivity是一个空的活动,只是为了尝试测试。

有什么想法吗? AndroidManifest.xml我可能会遗漏哪些东西?

1 个答案:

答案 0 :(得分:2)

如果有人遇到这个问题......当它再次从我的存储库中拔出时它就会自动解决。

必须使用Android Studio缓存执行某些操作。

相关问题