1

When I run my test method that uses Espresso, it prompts me to choose an emulator, and I pick my existing emulator with my application already started. The emulator subsequently automatically reboots my application, and then displays that that the test suite is empty.

The error

My espresso test case is located in the androidTest folder of the same module as the activity I'm trying to test. I wrote a simple "isDisplayed()" type of a test and right clicked the method and clicked run. I've taken a look at the other questions on Stack Overflow and other resources, but I can't figure out what is causing this problem. The logcat displays nothing and when I tried putting Log.d("debug", "hello hello") in the test method (shown below), nothing shows up in the logcat, nor does anything display when I try putting a System.out.println("hello") in the test method. It seems that although I run the method, none of my code is being run!

Below is some of my build.grade.

apply plugin: 'com.android.application'

android {
   compileSdkVersion 17
   buildToolsVersion "21.1.2"
   defaultConfig {
       applicationId "x"
       minSdkVersion 17
       targetSdkVersion 17
       versionCode 1
       versionName "1.0"

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


    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'LICENSE.txt'
    }
}


configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile 'com.android.support.test:rules:0.3'
    androidTestCompile 'com.android.support.test:runner:0.3'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
}

Here is the test case that I'm trying to run.

@RunWith(AndroidJUnit4.class)
public class EspressoTest1 extends ActivityInstrumentationTestCase2<P1>{


    private P1 mActivity;

    public EspressoTest1() {
        super(P1.class);
    }

    public void setUp() throws Exception {

        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        mActivity = getActivity();

    }

    public void Happy_test() {

        onView(withId(R.id.Btn)).check(matches(isDisplayed()));

    }
}

Test Configuration

And this is the test run configuration.

aashima
  • 1,203
  • 12
  • 31
Poptart
  • 331
  • 4
  • 16

2 Answers2

3

Your test is missing @Test annotation. So as your setup method is missing @Before

Be_Negative
  • 4,892
  • 1
  • 30
  • 33
  • Thanks, that did it after importing `@Test` and `@Before` from JUnit and then cleaning and rebuilding the project. – Poptart Jun 29 '15 at 20:56
  • That didn't fix my problem at all. In fact, I already had `@Test` and `@Before`. – IgorGanapolsky Oct 24 '16 at 22:12
  • 1
    @IgorGanapolsky `Empty Test Suite` can be literally any sort of issue - from gradle task failure to misconfigured @before method. In this case it was quite obvious from the question what the problem was. It might be something completely different in your case. – Be_Negative Oct 25 '16 at 13:49
  • Try making a new `Android Instrumented Tests` configuration manually in `Edit Configuration` https://stackoverflow.com/a/53715513/967131 – Chad Schultz Dec 11 '18 at 00:02
0

Maybe this will help other people (like Igor Ganapolsky).

When you are using annotations from Espresso library you have to add testInstrumenatationRunner to your gradle file. Missing this line occurs the same error message "Empty test suite"

defaultConfig {
    applicationId "com.test.app"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}