Fra*_*rez 10 testing android ui-automation gradle android-espresso
我有Android应用程序,我想使用Espresso框架来创建测试自动化工具和测试.但我不想在我的应用程序中创建一些东西,并希望使用Espresso的单独模块启动我的应用程序并使用Espresso进行测试.我使用Android Studio.那么..你有什么想法如何解决这个问题?
您可以使用专门用于仪器测试的库模块。基本上只是创建一个库模块但使用不同的插件:
apply plugin: 'com.android.test' // A plugin used for test-only-modules
Run Code Online (Sandbox Code Playgroud)
此外,您还需要android稍微更改测试模块中 build.gradle 文件中的部分:
android {
[...]
defaultConfig {
[...]
testApplicationId "com.yourcompany.yourapp.test"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
[...]
// Set the target app project.
// The module specified here should contain the
// production code test should run against.
targetProjectPath ':app'
}
Run Code Online (Sandbox Code Playgroud)
然后在测试模块的依赖项中添加您的应用程序和所有浓缩咖啡库等:
dependencies {
implementation project(':app')
// All your test dependencies etc.
implementation "androidx.test.espresso:espresso-core:$espresso_version"
}
Run Code Online (Sandbox Code Playgroud)
使用 gradle 同步并运行测试,您可以在本地执行测试。如果您需要在 Firebase 测试实验室等外部进行测试,您还将获得该模块的所有正常 gradle 任务,您可以使用这些任务来组装测试 APK 等。
| 归档时间: |
|
| 查看次数: |
375 次 |
| 最近记录: |