用gradle进行双重浓咖啡测试 - 空测试套件

时间:2014-06-14 22:25:53

标签: testing gradle android-studio android-espresso

我正在尝试用浓缩咖啡来测试我的药物。正如我在其他演讲中发现的那样,我将使用带有gradle的纯浓缩咖啡的双浓缩咖啡。可以在这里找到Doulbe浓缩咖啡:https://github.com/JakeWharton/double-espresso

我配置了这样的运行配置:http://wiki.android-test-kit.googlecode.com/git/android-studio-new-run-configuration.png。当我执行它时,一段时间后它会显示空测试套件

我在androidTest / java目录中创建了以下测试类: 包com.myapp.mobileapp.test.ui;

@LargeTest
public class LoginTest extends ActivityInstrumentationTestCase2<LoginActivity> {

    public LoginTest(Class<LoginActivity> activityClass) {
        super(activityClass);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    @SmallTest
    public void testLogin() {
        onView(withId(R.id.buttonLogin))
                .perform(click());
        assertTrue(true);
    }
}

我的项目有一个包含apk项目和facebook库项目的顶级项目。

顶级项目的构建文件如下:

// Top-level build file where you can add configuration options common to all     sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.11.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

apk项目的构建文件如下:

apply plugin: 'android'

android {
    compileSdkVersion 18
    buildToolsVersion "19.1.0"

    // https://code.google.com/p/android/issues/detail?id=71147
    useOldManifestMerger true

    defaultConfig {
        applicationId "com.myapp.mobileapp"
        minSdkVersion 14
        targetSdkVersion 18

        testApplicationId "com.myapp.mobileapp.test"   
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-    rules.txt'
        }
        debug {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-    rules.pro'
        }
    }

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

dependencies {

// OTHERS
    compile 'com.android.support:support-v4:18.0.0'
    compile('com.google.code.gson:gson:2.2.4')

    // GOOGLE PLAY SERVICES
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:3.2.65'

    // FACEBOOK
    compile project(':facebookSDK')

    // CHAT LIBRARY
    compile files('libs/asmack-android-18-0.8.10.jar')

    // GOOGLE ANALITICS
    compile files('libs/libGoogleAnalyticsServices.jar')

    // ORMLITE
    compile 'com.j256.ormlite:ormlite-core:4.41'
    compile 'com.j256.ormlite:ormlite-android:4.41'

    // ROBOSPICE
    compile('com.octo.android.robospice:robospice:1.4.6') {
        exclude module: 'support-v4'
    }
    compile('com.octo.android.robospice:robospice-spring-android:1.4.6') {
        exclude module: 'support-v4'
    }
    compile('org.codehaus.jackson:jackson-mapper-asl:1.9.11')

    // LOGGING
    compile files('libs/slf4j-api-1.7.5.jar')
    compile files('libs/logback-android-1.0.10-2.jar')

    // VOLLEY
    compile files('libs/volley.jar')

        // TESTING TOOLS    
        androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3')
    }

我使用以下工具:

Android Studio 0.6.1

(在android studio中建立gradle)gradlew --version

Gradle 1.10

建造时间:2013-12-17 09:28:15 UTC 内部编号:无 修订:36ced393628875ff15575fa03d16c1349ffe8bb6

的Groovy:1.8.6

Ant:Apache Ant(TM)版本1.9.2

常春藤:2.2.0

JVM:1.8.0_05(Oracle Corporation 25.5-b02)

操作系统:Windows 8.1 6.3 amd64

1 个答案:

答案 0 :(得分:0)

您可能会遇到异常,因此请查看日志。

构造函数需要像这样:

public LoginTest() {
    super(LoginActivity.class);
}

类似的问题和答案: Espresso testing android