繁体   English   中英

运行 Android 检测测试失败

[英]Run Android instrumented tests fail

我尝试为我的 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);
            }
        });
    }

}

当我尝试运行测试时,出现此错误:

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

我在 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'

我也遇到了这个问题。 我在“Android 测试”部分下的Android Studio Bumblebee 2021.1.1 发行说明中找到了解决方案。

它基本上相当于在测试设置中取消选中使用 Gradle 运行 Android 检测测试旁边的框。 这对我有用。

测试设置 Android Studio

解决方案是排除模块: protobuf-lite

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

正如这里提到的

禁用统一的 Gradle 测试运行器

默认情况下,Android Studio Bumblebee 使用 Gradle 运行其仪器测试。 如果您遇到问题,可以按如下方式禁用此行为:

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.

所以你可以禁用统一的 Gradle 测试运行器。

对我来说,问题是我在小米红米 Note 7 上运行。一旦我切换到模拟器。 一切正常。

暂无
暂无

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

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