2017-01-03 15 views
1

エスプレッソを使用してテストケースを実行できません。2.2.2例外をスローします。私はエラーを解決するための調査をしましたが、解決策を見つけられませんでした。問題を解決するのを手伝ってください。エスプレッソ:IllegalStateException:ライフサイクルモニタが登録されていません

java.lang.IllegalStateException:ライフサイクルモニタが登録されていません!ライフサイクルモニタを登録する計測器の下で動作していますか? android.support.test.espresso.base.BaseLayerModule.provideLifecycleMonitorでandroid.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry.getInstance(ActivityLifecycleMonitorRegistry.java:44) (BaseLayerModule.java:52)android.supportで で。 test.espresso.base.BaseLayerModule_ProvideLifecycleMonitorFactory.get(BaseLayerModule_ProvideLifecycleMonitorFactory.java:18)

のGradleアプリレベルのGradle

0で定義さ

dependencies { 
    compile project(':domain') 
    compile project(':data') 

    compile "com.squareup.leakcanary:leakcanary-android:1.3.1" 
    apt "com.google.dagger:dagger-compiler:2.0.2" 
    compile "com.android.support:appcompat-v7:23.4.0" 
    compile "com.google.dagger:dagger:2.0.2" 
    compile "com.jakewharton:butterknife:7.0.1" 
    compile "io.reactivex:rxjava:1.0.14" 
    compile "com.android.support:design:23.4.0" 
    compile "io.reactivex:rxandroid:1.0.1" 
    provided "javax.annotation:jsr250-api:1.0" 
    compile "com.android.support:support-annotations:21.0.3" 
    compile 'com.android.support:multidex:1.0.1' 

    androidTestCompile "org.mockito:mockito-core:1.10.19" 
    androidTestCompile "com.google.dexmaker:dexmaker:1.2" 
    androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2" 
    androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.2" 
    androidTestCompile "com.android.support.test:testing-support-lib:0.1" 
    androidTestCompile "com.android.support.test:runner:0.5" 
    androidTestCompile "com.android.support.test:rules:0.5" 
} 

カスタムテストランナーの依存関係

android { 
    defaultConfig { 
     testInstrumentationRunner "com.myapp.presentation.TestRunner" 
     multiDexEnabled true 
    } 
} 

カスタムテストランナーはこちら パッケージcom.myapp.presentation; commit on the Android clean architectureを確認しながら

public class TestRunner extends AndroidJUnitRunner 
{ 
    @Override 
    public void onCreate(Bundle arguments) 
    { 
     MultiDex.install(getTargetContext()); 
     super.onCreate(arguments); 
    } 
} 

がここに最後に私のテストクラス

import android.support.test.filters.LargeTest; 
import android.support.test.rule.ActivityTestRule; 
import android.support.test.runner.AndroidJUnit4; 

import org.junit.Rule; 
import org.junit.Test; 
import org.junit.runner.RunWith; 

import static android.support.test.espresso.Espresso.onView; 
import static android.support.test.espresso.assertion.ViewAssertions.matches; 
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 
import static android.support.test.espresso.matcher.ViewMatchers.withId; 

@RunWith(AndroidJUnit4.class) 
@LargeTest 
public class ProductDetailsActivityTest { 
    @Rule 
    public ActivityTestRule<ProductDetailsActivity> mActivityRule = new ActivityTestRule<>(ProductDetailsActivity.class); 

    @Test 
    public void listGoesOverTheFold() { 
     onView(withId(R.id.view_pager)).check(matches(isDisplayed())); 
    } 
} 

答えて

1

ですが、私は解決策を見つけました。

問題は、依存関係によるものであった

androidTestCompile "com.android.support.test:テスト・サポート-LIB:0.1" 私はこの依存関係を削除しているし、今私ができる午前に

Espresso-v2.2.2でテストケースを実行

関連する問題