Search code examples
androidandroid-espressoandroid-testingandroidx

AndroidX Espresso Test: No tests were found and Empty test suite


I am trying to run src/androidTest which is Instrument test in my Android Project which uses AndroidX libraries, but I am getting No tests were found error and Empty test suite log.

I have checked all samples and documents which are using AndroidX libraries are doing same.

I have tried to setup Edit Configurations based on following link https://stackoverflow.com/a/53715513/1826656 But still no luck.

Am I doing anything wrong? or missing any steps?

Please check this image for Test Run log

MainActivityTest.java Code:

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

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest {

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

   @Test
   public void checkViewsVisibility() {
     // verify the visibility of recycler view on screen
     onView(withId(R.id.record_list_rv)).check(matches(isDisplayed()));

     // verify the visibility of progressbar on screen
     onView(withId(R.id.progressBar)).check(matches(isDisplayed()));

     // verify the visibility of no data TextView on screen By default it should be GONE
     onView(withId(R.id.no_data_tv)).check(matches(isDisplayed()));

     onView(withId(R.id.no_data_tv)).check(matches(withText("No Data")));

     onView(withId(R.id.no_data_tv)).perform(typeText("No Data"));
   }
}

Gradle file dependencies:

android {
    defaultConfig {
       testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunne"
    }

    testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
    }
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestUtil 'androidx.test:orchestrator:1.1.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
}

Solution

  • You have a typo in your defaultConfig. It should probably be:

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"