2016-02-18 10 views
7

エスプレッソを使用してテストケースを作成しようとしています。Androidスタジオでエスプレッソのインポートが認識されない

私はAndroid Studio 1.5.1(安定チャンネル)、Gradleプラグイン1.5、Gradle 2.7を使用しています。 問題は、Android Studioはエスプレッソに関連するすべてのインポート(だけではなく)

enter image description hereだから、私は、プロジェクトをきれいに再構築し、キャッシュと再起動、何もを無効にしようとしたが認識されないということです。

enter image description here

:私はandroidTestフォルダの下のテストスイートクラスを作成し

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

:私はdefaultConfigでランナーを追加

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
androidTestCompile 'com.android.support:support-annotations:23.1.1' 
androidTestCompile 'com.android.support.test:runner:0.4.1' 
androidTestCompile 'com.android.support.test:rules:0.4.1' 

は、私は私のアプリモジュールでこれらの依存関係を追加しました

私は間違って何をしていますか?

UPDATEここ

は私のbuild.gradleの(一部)である:Androidのメーカーで

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 

android { 
    compileSdkVersion 23 
    buildToolsVersion '23.0.2' 

    defaultConfig { 
     minSdkVersion 15 
     targetSdkVersion 23 
     versionCode 5 
     versionName '1.4' 

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

    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 

    buildTypes { 
     //my build type configs 
    } 

    packagingOptions { 
     exclude 'META-INF/services/javax.annotation.processing.Processor' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/NOTICE.txt' 
    } 

    lintOptions { 
     disable 'InvalidPackage' 
    } 

    dexOptions { 
     incremental true 
     preDexLibraries = false 
     jumboMode = false 
     javaMaxHeapSize "2g" 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.viewpagerindicator:library:2.4.1' 
    compile project(':libraries:RITracking') 
    compile 'com.android.support:support-v4:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
    compile 'com.android.support:support-annotations:23.1.1' 
    compile 'com.android.support:recyclerview-v7:23.1.1' 
    compile 'com.android.support:cardview-v7:23.1.1' 
    compile 'com.android.support:gridlayout-v7:23.1.1' 
    compile 'com.google.code.gson:gson:2.5' 
    compile 'com.google.android.gms:play-services-plus:8.4.0' 
    compile 'com.google.android.gms:play-services-base:8.4.0' 
    compile 'de.greenrobot:eventbus:2.4.1' 
    compile 'com.squareup.retrofit:retrofit:1.9.0' 
    compile 'com.squareup.okhttp:okhttp:2.7.2' 
    compile 'com.facebook.android:facebook-android-sdk:4.9.0' 
    compile 'com.cocosw:bottomsheet:[email protected]'       //Bottom Sheet that implement material design used for ShareDialog 
    compile 'com.github.bumptech.glide:glide:3.6.1'      //Glide library 
    compile 'com.googlecode.libphonenumber:libphonenumber:7.2.3'  //Library used to parse/merge phones number to E164 format 
    compile 'me.leolin:ShortcutBadger:[email protected]'      //Used to show badge on application icon, library is optimized to work on most of devices 
    compile 'com.stripe:stripe-android:1.0.3'        //Stripe payment gateway, used to integrate credit card payment 
    provided 'org.projectlombok:lombok:1.16.6' 
    apt "org.projectlombok:lombok:1.16.6" 
    compile 'com.jakewharton:butterknife:7.0.1' 
    apt "com.jakewharton:butterknife:7.0.1" 
    compile 'de.greenrobot:greendao:2.1.0'        //Green Dao library is ORM implementation for Android SQL lite 
    compile files('libs/libammsdk.jar') 
    compile files('libs/apptimize-android-2.9.1.jar') 

    testCompile 'junit:junit:4.12' 

    androidTestCompile "com.android.support:support-annotations:23.1.1" 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' 
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') { 
     exclude group: 'com.android.support', module: 'appcompat' 
     exclude group: 'com.android.support', module: 'support-v4' 
     exclude module: 'recyclerview-v7' 
    } 
    androidTestCompile 'com.android.support.test:runner:0.4.1' 
    androidTestCompile 'com.android.support.test:rules:0.4.1' 
} 

答えて

0

オープンファイル名を指定して実行]メニュー - >編集の設定 - 新しいアンドロイドを追加テスト構成 - モジュールを選択 特定の計装ランナーを追加:

android.support.test.runner.AndroidJUnitRunner

また、SDKマネージャからAndroidサポートライブラリを更新しようとしています。

これが役に立った。 次のトピックを試すこともできます。link

幸運を祈る!

+0

すでに試したところ、utはAndroidJUnitRunnerを見つけることができません。サポートライブラリが更新されました。 –

+0

Ok ...解決策はまだ見つかりましたか? – sunlover3

+0

まだ解決されていません。 build.gradleで質問を更新しました。 –

1

あなたの設定には何か不足していることは間違いありません。

def ASVersion = '23.1.1' 

buildscript { 
    repositories { 
     maven { url 'https://maven.fabric.io/public' } 
    } 

    dependencies { 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 
apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 
apply plugin: 'com.neenbedankt.android-apt' 

repositories { 
    maven { url 'https://maven.fabric.io/public' } 
} 


android { 
    dataBinding { 
     enabled = true 
    } 
    compileSdkVersion 23 
    buildToolsVersion '23.0.2' 

    defaultConfig { 
     applicationId "com.piotr.awesome" 
     minSdkVersion 16 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 

    androidTestCompile "com.android.support:support-annotations:$ASVersion" 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' 
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') { 
     exclude group: 'com.android.support', module: 'appcompat' 
     exclude group: 'com.android.support', module: 'support-v4' 
     exclude module: 'recyclerview-v7' 
    } 
    androidTestCompile 'com.android.support.test:runner:0.4.1' 
    compile "com.android.support:appcompat-v7:$ASVersion" 
    compile "com.android.support:support-v4:$ASVersion" 
    compile "com.android.support:design:$ASVersion" 

} 

の下に地雷を使用してbuild.gradleを比較する。またFile -> Invalidate cache/restartを選択し、最初のオプションを試してみてください。

は@Jaymesベアデンは以下のコメントで言っただけのように、それは

+0

piotrekに感謝します。でも同じ問題です。 build.gradleで質問を更新しました。私は見てみたいかもしれない。 –

+0

@DanieleVitali、問題は修正されましたか? – piotrek1543

+0

残念ながら、私はもうそのプロジェクトに取り組んでいません。しかし、私はcanary channelでASを使って他のプロジェクトでExpressoテストをうまく実行することができます。 –

4

UPDATE 30/11/2016

を助け願っています。

testBuildTypeを使用してください。 Android Studio 2.2、gradle 2.2。2

android { 
     testBuildType "yourBuildType" 
} 

OLD ANSWER

私は解決策が、問題のいくつかのソースが見つかりません。私のプロジェクトでは、たくさんのBuildTypesがあります。特に複数のデバッグビルド。

すべてはデフォルトでのみ動作しますデバッグビルドタイプ。私はこれがAndroid Studioの内部エラーだと思う。

私のASバージョン - 2.1

+1

これはまさに私の問題でした。私にはたくさんのバリエーションがあり、間違ったものを選んでいました。私はオプションを見つけましたが、あなたはアンドロイドキーの下であなたのアプリのgradle.buildで "testBuildType"オプションを使うことができます。あなたが望む任意の変種に設定してください。 –

+0

@Arturこれは何ですかtestBuildType "yourBuildType"どこで変更する必要がありますか –

2

デバッグビルドバリアントを使用する必要があります。他のビルドオプションでは、エスプレッソは認識されません。

2

おそらく、あなたのビルドバリアントは "リリース"モードになっています。それをデバッグするために変更する必要があります。 enter image description here

関連する問題