我有android应用程序,我想使用Espresso框架来创建测试自动化工具和测试。但我不想在我的应用程序中创建的东西,并希望独立的模块与浓缩咖啡,将启动我的应用程序,并使用浓缩咖啡测试它。我使用Android Studio。所以. .你有什么办法解决这个问题吗?
您可以使用专门用于仪表测试的库模块。基本上只是创建一个库模块,但使用不同的插件:
apply plugin: 'com.android.test' // A plugin used for test-only-modules
您还需要在构建中更改您的android
部分。在你的测试模块中添加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任务,如果您需要它在外部进行测试,例如在Firebase测试实验室中,您可以使用它来组装测试APK等。