我有 android 应用程序,我想使用 Espresso 框架来创建测试自动化工具和测试。但是我不想在我的应用程序中创建一些东西,并且想要使用 Espresso 的单独模块来启动我的应用程序并使用 Espresso 对其进行测试。我使用安卓工作室。所以..你有什么想法如何解决这个问题吗?
最佳答案
您可以使用 library module specialised for instrumentation tests .基本上只是创建一个库模块,但使用不同的插件:
apply plugin: 'com.android.test' // A plugin used for test-only-modules
您还需要更改您的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'
}
然后在测试模块的依赖项中添加您的应用程序和所有 espresso 库等:dependencies {
implementation project(':app')
// All your test dependencies etc.
implementation "androidx.test.espresso:espresso-core:$espresso_version"
}
使用 gradle 同步和运行测试,您可以在本地执行测试。如果您需要它进行外部测试,您还将获得该模块的所有正常 gradle 任务,您可以使用这些任务来组装您的测试 APK 等。在 Firebase 测试实验室中。
关于android - 在单独的模块中进行 Espresso 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31272191/