2

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'
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
rjkolli7
  • 153
  • 3
  • 9
  • Relevant related question: https://stackoverflow.com/questions/53600222/no-tests-found-when-running-instrumented-tests-with-androidx – Alexandre Sep 06 '19 at 21:11

3 Answers3

2

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

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
devaga
  • 326
  • 2
  • 15
  • Correcting a typo was also the solution in a case where I had created a custom `testInstrumentationRunner`, moved it to a new package, but forgot to update the value in the `build.gradle` file. Unfortunately neither Android Studio nor `./gradlew :app:connectedAndroidTest` told me it could not find the runner, they just gave error messages that `No tests were found`. – Michael Osofsky Dec 04 '19 at 00:11
0

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.

Demigod
  • 5,073
  • 3
  • 31
  • 49
-1

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

Darotudeen
  • 1,914
  • 4
  • 21
  • 36