微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

运行Espresso测试时,在Android Studio中找不到android:forceQueryable属性

如何解决运行Espresso测试时,在Android Studio中找不到android:forceQueryable属性

我已经使用运行菜单中的android studio 记录Espresso测试选项记录了我的android应用Espresso测试。在记录的末尾,我用自己的文件名保存了测试。

单击保存按钮后,IDE会自动 app 模块的 AndroidTest 目录中创建文件。我右键单击保存的文件,然后单击运行。然后它提示我以下错误

/Users/dehanwijesekara/Documents/ProjectName/app/build/intermediates/packaged_manifests/debugAndroidTest/AndroidManifest.xml:24: AAPT: error: attribute android:forceQueryable not found.

以下是上面链接中的文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dehan.pizzago.test" >

<uses-sdk
    android:minSdkVersion="23"
    android:targetSdkVersion="29" />

<instrumentation
    android:name="androidx.test.runner.AndroidJUnitRunner"
    android:functionalTest="false"
    android:handleProfiling="false"
    android:label="Tests for com.dehan.pizzago"
    android:targetPackage="com.dehan.pizzago" />

<queries>
    <package android:name="androidx.test.orchestrator" />
    <package android:name="androidx.test.services" />
    <package android:name="com.google.android.apps.common.testing.services" />
</queries>

<uses-permission android:name="android.permission.REORDER_TASKS" />

<application
    android:debuggable="true"
    android:extractNativeLibs="false"
    android:forceQueryable="true" >
    <uses-library android:name="android.test.runner" />

    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
        android:theme="@android:style/Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
        android:theme="@android:style/Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
</application>

我正在使用Android Studio 4.1

请咨询。

解决方法

这就是我所做的。

在浓咖啡录制结束时,我注意到Android Studio自动将以下库添加到应用程序级别的Gradle build.xml文件中。

androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha02'

以下是我根据espresso setup guide in google android developers document手动添加的其他库。

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'

然后我将上述库更新为以下最新版本(因为android studio建议使用最新版本,所以我进行了更新)。

androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'

然后,使espresso-contrib的版本等于espresso-core,如下所示:

androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'

请注意,现在espresso-contribespresso-core的版本均为3.3.0

我也从我的gradle构建文件中删除了以下库,但尚未检查,如果它们连续存在会发生什么情况。因为我的目的不是要测试,而是要像机器人程序一样连续执行任务。

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'

最后,它成功了,我认为问题中上述错误的原因是版本不匹配。

,

就我而言,此配置有效。

androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha03'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha03'
androidTestImplementation 'androidx.test:runner:1.3.1-alpha03'
androidTestImplementation 'androidx.test:rules:1.3.1-alpha03'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。