如果我的应用程序与Robolectric运行

如果我的应用程序与Robolectric运行

本文介绍了我怎么知道,如果我的应用程序与Robolectric运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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);
}

这篇关于我怎么知道,如果我的应用程序与Robolectric运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:05