Issue
I am not able to execute test cases using espresso-2.2.2 it throws below exception. I did research to solve error but do not found the solution. Please help me to fix the issue.
java.lang.IllegalStateException: No lifecycle monitor registered! Are you running under an Instrumentation which registers lifecycle monitors? at android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry.getInstance(ActivityLifecycleMonitorRegistry.java:44) at android.support.test.espresso.base.BaseLayerModule.provideLifecycleMonitor(BaseLayerModule.java:52) at android.support.test.espresso.base.BaseLayerModule_ProvideLifecycleMonitorFactory.get(BaseLayerModule_ProvideLifecycleMonitorFactory.java:18)
Gradle dependencies
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"
}
Custom test runner defined in app level gradle
android {
defaultConfig {
testInstrumentationRunner "com.myapp.presentation.TestRunner"
multiDexEnabled true
}
}
Custom test runner is here package com.myapp.presentation;
public class TestRunner extends AndroidJUnitRunner
{
@Override
public void onCreate(Bundle arguments)
{
MultiDex.install(getTargetContext());
super.onCreate(arguments);
}
}
Here is my test class
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()));
}
}
Solution
Finally, I found the solution while checking the commit on the Android clean architecture.
Problem was due to dependency
androidTestCompile "com.android.support.test:testing-support-lib:0.1"
I have removed this dependency and now I am able to execute the test cases with Espresso-v2.2.2
Answered By - Dharmendra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.