2017-05-13 2 views
1

エスプレッソライブラリを使用してプロジェクトでアンドロイド計測器テストを設定しようとしています。問題は、テストクラスがコンパイルに失敗することです(gradle task:compileDebugJavaWithJavac)。 私のGradleの設定ファイル:Android 25とEspresso 2.2.2が計測器テストアノテーションに失敗する

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath group: 'com.android.tools.build', name: 'gradle', version: libVersions.android.androidTools 
     classpath group: 'org.greenrobot', name: 'greendao-gradle-plugin', version: libVersions.android.greendao 
    } 
} 

apply plugin: 'com.android.application' 
android { 
    compileSdkVersion configuration.targetSdkVersion 
    buildToolsVersion configuration.buildToolsVersion 

    defaultConfig { 
     applicationId 'com.example.vbp.android' 
     minSdkVersion 23 
     targetSdkVersion 25 
     maxSdkVersion 25 
     versionCode buildVersionCode() 
     versionName buildVersionName() 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

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

    sourceSets { 
     main { 
      java { 
       srcDirs += new File("src/main/java-gen") 
      } 
     } 
     androidTest.setRoot('src/androidTest') 
    } 
} 

apply plugin: 'org.greenrobot.greendao' 
greendao { 
    schemaVersion 1 
    targetGenDir 'src/main/java-gen' 
    generateTests true 
} 

tasks.withType(Test) { 
    testLogging { 
     exceptionFormat "full" 
     events "started", "skipped", "passed", "failed" 
     showStandardStreams true 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile group: 'com.android.support', name: 'appcompat-v7', version: 25.3.1 
    compile group: 'org.greenrobot', name: 'greendao', version: 3.2.0 
    //Injection 
    compile "javax.annotation:jsr250-api:1.0" 
    compile "com.google.dagger:dagger:2.4" 
    annotationProcessor "com.google.dagger:dagger-compiler:2.4" 

    testCompile group: 'junit', name: 'junit', version: 4.12 
    testCompile group: 'org.robolectric', name: 'robolectric', version: 3.3.1 

    androidTestCompile "junit:junit:${libVersions.test.junit}" 
    androidTestCompile('com.android.support.test:runner:0.5', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    androidTestCompile('com.android.support.test:rules:0.5', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    // Optional -- Hamcrest library 
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3' 
    // Optional -- UI testing with Espresso 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    // Optional -- UI testing with UI Automator 
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2' 
} 

依存関係ツリー:

androidTestCompile - Classpath for compiling the androidTest sources. 
+--- junit:junit:4.12 
| \--- org.hamcrest:hamcrest-core:1.3 
+--- com.android.support.test:runner:0.5 
| +--- junit:junit:4.12 (*) 
| \--- com.android.support.test:exposed-instrumentation-api-publish:0.5 
+--- com.android.support.test:rules:0.5 
| \--- com.android.support.test:runner:0.5 (*) 
+--- org.hamcrest:hamcrest-library:1.3 
| \--- org.hamcrest:hamcrest-core:1.3 
+--- com.android.support.test.espresso:espresso-core:2.2.2 
| +--- com.squareup:javawriter:2.1.1 
| +--- com.android.support.test:rules:0.5 (*) 
| +--- com.android.support.test:runner:0.5 (*) 
| +--- javax.inject:javax.inject:1 
| +--- org.hamcrest:hamcrest-library:1.3 (*) 
| +--- com.android.support.test.espresso:espresso-idling-resource:2.2.2 
| +--- org.hamcrest:hamcrest-integration:1.3 
| | \--- org.hamcrest:hamcrest-library:1.3 (*) 
| +--- com.google.code.findbugs:jsr305:2.0.1 
| \--- javax.annotation:javax.annotation-api:1.2 
\--- com.android.support.test.uiautomator:uiautomator-v18:2.1.2 

不良のテストクラス:

package com.example.vbp.android.activities.splash; 

import android.support.test.filters.MediumTest; 
import android.support.test.runner.AndroidJUnit4; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import static junit.framework.Assert.assertTrue; 

@RunWith(AndroidJUnit4.class) 
@MediumTest 
public class SplashActivityTest { 

    @Test 
    public void assureActivityIsLaunching() { 
     assertTrue(true); 
    } 
} 

そしてGradleのコンパイル結果:

Error:(3, 36) error: package android.support.test.filters does not exist 
Error:(4, 35) error: package android.support.test.runner does not exist 
Error:(5, 17) error: package org.junit does not exist 
Error:(6, 24) error: package org.junit.runner does not exist 
Error:(9, 2) error: cannot find symbol class RunWith 
Error:(10, 2) error: cannot find symbol class MediumTest 
Error:(13, 6) error: cannot find symbol class Test 
Error:Execution failed for task ':VBPAndroid:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

REMARK私の気持ちは、コンパイラがのAssert.assertTrue junitのインポートだけですが、他の人の中ではorg.junit.Test annotationについて不平を言っていないので、アノテーションに関する問題があるということです。

ご協力ありがとうございました。

答えて

0

いいえ、私は原因を見つけて修正することができました。実際、GreenDaoのフラグgenerateTestsをTRUEに設定すると、依存関係の問題が発生しました。 新しいバージョンのGreenDao(3.2.0 - > 3.2.2)にアップグレードするだけで解決しました。

関連する問題