`RenamingDelegatingContext` 已弃用.我们现在如何测试 SQLite 数据库? [英] `RenamingDelegatingContext` is deprecated. How do we test SQLite db now?

查看:27
本文介绍了`RenamingDelegatingContext` 已弃用.我们现在如何测试 SQLite 数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 https://stackoverflow.com/a/13556184/3286489,我们可以使用 RenamingDelegatingContext 用于帮助 Android 开发的 SQLite DB 单元测试.

As per https://stackoverflow.com/a/13556184/3286489, we could use RenamingDelegatingContext for aiding the SQLite DB unit test for Android development.

然而,在 API 级别 24 开始时,android doc 宣布这现在已弃用.那么我们可以用什么新方法来代替 RenamingDelegatingContext?

However in beginning API level 24, android doc announced that this is now deprecated. So what is the new approach of testing we could do in replacing RenamingDelegatingContext?

推荐答案

我找到了一个解决方案,我们可以使用 Robolectric 的 RuntimeEnvironment.application 作为上下文,其他的就直接了作为正常的单元测试过程.

I have found a solution, where we could just use Robolectric's RuntimeEnvironment.application as the Context, and the others would be straight forward as normal Unit test process.

如果需要更多详细信息,请参阅此内容,其中包含完整的 Android SQLite DB 单元测试代码.https://medium.com/@elye.project/android-sqlite-database-unit-testing-is-easy-a09994701162#.rhdv2qa9o

In case if more details is needed, do refer to this, that has complete code of having Android SQLite DB unit tested. https://medium.com/@elye.project/android-sqlite-database-unit-testing-is-easy-a09994701162#.rhdv2qa9o

这篇关于`RenamingDelegatingContext` 已弃用.我们现在如何测试 SQLite 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆