我怎么知道,如果我的应用程序与Robolectric运行?我的、应用程序、我怎么、Robolectric

2023-09-05 02:33:39 作者:山川皆无恙

我有一个Android应用程序,使用ORMLite / SQLite的,我用Robolectric结合JUnit 4中,让我跑在Android的工作室,并在詹金斯构建服务器的单元测试。

I have an android app that uses ORMLite/SQLite and I use Robolectric in conjunction with JUnit 4 to allow me to run unit tests in Android Studio and on a Jenkins build server.

通常我会在我的测试设置的测试数据,在安装程序,然后运行我的测试场景反对它,但是当我试图做到这一点我开始这似乎是有关文件的问题和异常被锁定或东西,这似乎是一个问题,别人有过...所以我做了什么到现在为止是用我的数据库助手创建数据库的方法来创建一些该测试预计在那里虚拟数据。

Typically I would setup test data in my tests, in the setup, and then run my test scenarios against it but when I tried to do this I started getting issues and exceptions which seemed to be related to files being locked or something and that seems to be a problem others have had... so what I have done up until now is use the create database method in my database helper to create some dummy data which the tests expect to be there.

现在的问题是我的应用程序现在需要插入到一个真实的数据库,我不能把它设置虚拟数据在运行时。

The problem is my application now needs to plug into a real database and I can't have it setup dummy data when it runs.

如果有办法,在我的数据库辅助类,以检测code正在执行一个设备或在Robolectric?

If there a way, within my database helper class, to detect if the code is executing on a device or within Robolectric?

推荐答案

这是很适合我的Robolectric 3。

This is what works well for me on Robolectric 3.

public static boolean isRoboUnitTest() {
    return "robolectric".equals(Build.FINGERPRINT);
}
 
精彩推荐
图片推荐