gpt4 book ai didi

android - 如何使用任何模拟 Api for junit 模拟蓝牙适配器

转载 作者:太空狗 更新时间:2023-10-29 13:57:28 25 4
gpt4 key购买 nike

我正在尝试为我在 android 中的蓝牙代码测试编写 junit 测试用例。我的公共(public)方法尝试调用蓝牙适配器,但它给出错误,如 java.lang.RuntimeException: Method getDefaultAdapter in android.bluetooth.BluetoothAdapter not mocked。

如有任何帮助,我们将不胜感激。

最佳答案

Android 框架中的 BluetoothAdapter 被声明为 final,因此不能使用 Mockito 或 Robolectric 对其进行模拟。但是,可以使用 PowerMock。看看this example .

关于android - 如何使用任何模拟 Api for junit 模拟蓝牙适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38310300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com