Jagaur
Jagaur

Reputation: 51

UI Testing with Espresso

I am writing the below code it shows me error at ActivityTestRule it displays cannot find declaration to go,does it not come inbuilt in Espresso

@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
        MainActivity.class); 

Upvotes: 1

Views: 297

Answers (3)

anuja jain
anuja jain

Reputation: 1387

It is part of Espresso but check whether you have added Espresso like shown below in build.gradle plus android test support library and sync the gradle.

androidTestCompile'com.android.support.test:runner:0.4.1'  
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') 

Upvotes: 1

Prem Choudhary
Prem Choudhary

Reputation: 210

To setup espresso please follow the following steps:-

Step 1: At first add the dependencies in your build.gradle file.

//Espresso Dependencies
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:rules:0.5'`

Step 2: Go to Run -> Edit Configuration -> Click on the "+" symbol on the upper left and then click on Android Test. The in the General tab select your module which you want to test and then add this "android.support.test.runner.AndroidJUnitRunner" in the Specific Instrumentation Runner and the Click Ok.

Step 3: In your test case file add the following imports.

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Rule;
import org.junit.runner.RunWith; 

Upvotes: 0

sunlover3
sunlover3

Reputation: 2049

Did you added the instrumentation runner?

enter image description here

Upvotes: 0

Related Questions