20

I tried to implement some unit and instrumented tests for my Android application (Java), my unit tests is working fine but instrumented tests are failing:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ExampleInstrumentedTest {
    @Rule
    public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class);


    @Test
    public void checkIfCategoriesIsNotEmpty() {
        onView(withId(R.id.header_left_layout)).perform(click());
        onView(withId(R.id.list_view)).check(new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noViewFoundException) {
                ListView list_categories = (ListView) view;
                ListAdapter adapter = list_categories.getAdapter();
                Assert.assertTrue(adapter.getCount() > 0);
            }
        });
    }

}

When I try to run my test I got this error :

"Run Android instrumented tests using Gradle" option was ignored because this module type is not supported yet.

My Implementations in build.config file are :

 // UNIT TEST
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'

    // INSTRUMENTED TEST
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
NizarETH
  • 969
  • 3
  • 15
  • 38

5 Answers5

27

I just ran into this problem, too. I found the solution in the Android Studio Bumblebee 2021.1.1 release notes under the "Android testing" section.

It basically amounts to unchecking the box next to Run Android instrumented tests using Gradle in the testing settings. This worked for me.

Testing settings Android Studio

FireZenk
  • 1,056
  • 1
  • 16
  • 28
Ben
  • 371
  • 2
  • 3
  • 1
    Thanks, Ben, an additional screenshot would be a quick +1 – Shubham AgaRwal May 06 '22 at 12:37
  • 19
    Although this prevented the error message, no test actually ran in my case. Not even an error message, it just simply did nothing. The Test Results panel shows the `adb shell` command to run the test but I saw nothing run on the emulator and no results in the Test Results panel. – Michael Osofsky May 19 '22 at 18:45
  • 2
    I ran into the same issue as @MichaelOsofsky and it turned out to be the application crashing. Check logcat and you should see a stack trace – Selali Adobor Aug 28 '22 at 00:46
2

the solution is to exclude module: protobuf-lite :

 androidTestImplementation('androidx.test.espresso:espresso-contrib:3.4.0') {
        exclude module: "protobuf-lite"
    }
NizarETH
  • 969
  • 3
  • 15
  • 38
2

As mentioned here

Disable the unified Gradle test runner

By default Android Studio Bumblebee uses Gradle to run its instrumentation tests. If you're experiencing issues, you can disable this behavior as follows:

Select File > Settings > Build, Execution, Deployment > Testing (or Android Studio > Preferences > Build, Execution, Deployment > Testing on MacOS.)
Uncheck the box next to Run Android instrumented tests using Gradle and click OK.

So you can just disable the unified Gradle test runner.

rabyunghwa
  • 178
  • 3
  • 24
0

For me, the issue was that I was running on Xiaomi Redmi note 7. Once I switched to the emulator. everything worked fine.

0

Make sure to add

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Under defaultConfig inside the build.gradle module file.

Ahmed Maad
  • 367
  • 5
  • 16