Friday, 24 February 2023

Android Espresso Test case cancelled

I am executing the following espresso code. This code is working fine.

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

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

@RunWith(AndroidJUnit4.class)
public class EspressoTest {
    @Rule
    public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);

    @Test
    public void view_isCorrect() {
        onView(withText("Cash less")).check(matches(isDisplayed()));
    }
}

But ActivityTestRule is deprecated. Instead of this I am trying to use ActivityScenarioRule. But the same code using of ActivityScenarioRule is showing Test Cancelled.

After modify the code will will look like following.

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;

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

@RunWith(AndroidJUnit4.class)
public class EspressoTest {
    @Rule
    public ActivityScenarioRule<MainActivity> activityScenarioRule = new ActivityScenarioRule<>(MainActivity.class);

    @Test
    public void view_isCorrect() {
        onView(withText("Cash less")).check(matches(isDisplayed()));
    }
}

I am getting following error: Error image

I am using the following dependency in Gradle.

androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'

And also included testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' in the default block.

I tried with updating/degrade the version. Tried another versions too. And also I tried the following Solution: Link

But no luck. Please help me to resolve this issue.

I am setting compileSdkVersion is 33.



from Android Espresso Test case cancelled

No comments:

Post a Comment