简体   繁体   English

运行 Android 检测测试失败

[英]Run Android instrumented tests fail

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:我尝试为我的 Android 应用程序 (Java) 实现一些单元测试和仪器测试,我的单元测试工作正常,但仪器测试失败:

@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 :我在 build.config 文件中的实现是:

 // 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'

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.我在“Android 测试”部分下的Android Studio Bumblebee 2021.1.1 发行说明中找到了解决方案。

It basically amounts to unchecking the box next to Run Android instrumented tests using Gradle in the testing settings.它基本上相当于在测试设置中取消选中使用 Gradle 运行 Android 检测测试旁边的框。 This worked for me.这对我有用。

测试设置 Android Studio

the solution is to exclude module: protobuf-lite :解决方案是排除模块: protobuf-lite

 androidTestImplementation('androidx.test.espresso:espresso-contrib:3.4.0') {
        exclude module: "protobuf-lite"
    }

As mentioned here正如这里提到的

Disable the unified Gradle test runner禁用统一的 Gradle 测试运行器

By default Android Studio Bumblebee uses Gradle to run its instrumentation tests.默认情况下,Android Studio Bumblebee 使用 Gradle 运行其仪器测试。 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.所以你可以禁用统一的 Gradle 测试运行器。

For me, the issue was that I was running on Xiaomi Redmi note 7. Once I switched to the emulator.对我来说,问题是我在小米红米 Note 7 上运行。一旦我切换到模拟器。 everything worked fine.一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM