问题描述
我已经使用运行菜单中的android studio 记录Espresso测试选项记录了我的android应用Espresso测试.在记录的末尾,我用自己的文件名保存了测试.
I have recorded my android app Espresso test using android studio Record Espresso Test option in Run menu. In the end of the record I saved the test with a my own file name.
单击保存按钮后,IDE会在 app 模块的 AndroidTest 目录中自动创建文件.我右键单击保存的文件,然后单击运行.然后它提示我以下错误.
Once click the save button, IDE automatically created the file in AndroidTest directory of the app module. I right click the saved file and clicked run. Then it prompting me the following error.
/Users/dehanwijesekara/Documents/ProjectName/app/build/intermediates/packaged_manifests/debugAndroidTest/AndroidManifest.xml:24:AAPT:错误:属性android:forceQueryable未找到.
以下是上面链接中的文件.
following is the file in the above link.
<?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
I'm using Android Studio 4.1
请咨询.
推荐答案
这就是我所做的.
在浓咖啡录制结束时,我注意到Android Studio自动将以下库添加到应用程序级别的Gradle build.xml
文件中.
At the end of the espresso recording, I noticed Android Studio automatically adds the following library to the Gradle build.xml
file of the app level.
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha02'
以下是我根据 Google中的浓咖啡设置指南由我自己手动添加的其他库android开发人员文档.
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建议了最新版本,所以我进行了更新).
Then I updated the above libraries to the latest versions as below(Because android studio suggested the latest versions, so I updated).
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
如下
Then I make the versions of espresso-contrib
equal to espresso-core
as below
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'
请注意,现在 espresso-contrib
和 espresso-core
的版本都为 3.3.0
note, now both espresso-contrib
and espresso-core
having the version of 3.3.0
我也从gradle构建文件中删除了以下库,但尚未检查,如果它们连续保留会发生什么情况.因为我的目的不是要测试,而是要像机器人程序一样连续执行任务.
I removed the following libraries from my gradle build file also, haven't checked, what happened if they stay continuously. because my purpose is not to test but do a task continuously as a kind of robot program.
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
最后,它奏效了,我认为问题中上述错误的原因是版本不匹配.
Finally, it worked, I assume the reason for the above error in the question is because of the version mismatch.
这篇关于运行Espresso测试时,在Android Studio中找不到android:forceQueryable属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!