java - 使用模拟位置测试应用程序时出现 Android 错误

标签 java android unit-testing android-studio gps

我正在尝试测试我的 Android 基于位置的应用程序。

如果我可以在单元测试中模拟来自提供商的位置数据,那将非常有用。但我无法向 androidManifest.xml 添加 ACCESS_MOCK_LOCATION 权限,因为当我这样做时,它会给我一个错误:

Mock locations should only be requested in a debug-specific manifest file (typically src/debug/AndroidManifest.xml) Using a mock location provider (by requiring the permission android.permission.ACCESS_MOCK_LOCATION) should only be done in debug builds. In Gradle projects, that means you should only request this permission in a debug source set specific manifest file. To fix this, create a new manifest file in the debug folder and move the element there. A typical path to a debug manifest override file in a Gradle project is src/debug/AndroidManifest.xml.

但是当我将 AndroidManifest.xml 添加到 src/androidTest 目录时 - 它在测试时会忽略它。

我做错了什么?

最佳答案

我刚刚遇到了这个问题,我想我找到了解决方案。确保在您的设备开发者选项中选中“访问模拟位置”(此外还创建一个“src/debug/AndroidManifest.xml”文件声明 ACCESS_MOCK_LOCATION 权限的使用,就像您已经在做的那样)。

关于java - 使用模拟位置测试应用程序时出现 Android 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27502712/

相关文章:

java - 带线程的格乘,效率更高吗?

java - 错误 : Alias name [null] does not identify a key entry during implementing SSL in Tomcat

Java指南 : Deep object injection

javascript - Chromecast window.location.reload(true) 抛出未定义

amazon-web-services - 模拟AWS Go SSM GetParameter调用

java - SWT FileDialog 中的 PathMustExists 和 FileMustExists

java - Android - 添加按钮标题时的随机整数值

Android自定义 View 组委托(delegate)addView

c# - 如何对调用服务总线队列客户端 SendAsync 方法的类进行单元测试

java - 单击第二个 Activity 的按钮在 View 上执行 'single click' 或 'scroll to' 时出错