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

Viewed 2612

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'
}
3 Answers

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

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

In my case, I also struggled to run UI tests. Checking (and trying) most of the things in similar topics gave no results for me. Finally I ran my instrumentation tests via gradle command:

gradlew connectedProdDebugAndroidTest

or (if you want to run single test, or tests in a single class)

gradlew connectedProdDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class={package.class}#{methodName}

After running tests by command, somehow, it became possible to run them by dedicated button.

For me after ensuring that all dependencies were available, changing the targetSdk from 30 to lower version solved my problem.

Related