是否有可能找出是否一个Android应用程序作为仪器测试的一部分运行 [英] Is is possible to find out if an Android application runs as part of an instrumentation test

查看:154
本文介绍了是否有可能找出是否一个Android应用程序作为仪器测试的一部分运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个运行时检查应用程序,以找出是否它作为一个仪器测试的一部分运行。

Is there a runtime check for an application to find out if it runs as part of an instrumentation test.

背景:出应用程序启动时执行数据库同步。但是,应该只有当一个普通的开始发生。贝斯它干扰与仪器测试测试数据库同步。毫不奇怪。

Background: Out application performs an database sync when starting. But that should happen only when a regular start. Especial it interferers with the instrumentation tests testing the db sync. Not surprisingly.

和所有其他的测试中,它只是浪费CPU周期。

And with all the other tests it is just a waste of CPU cycles.

推荐答案

如果您使用的是ActivityUnitTestCase,你可以设置setApplication自定义应用程序对象,并在那里有一个标志来打开或关闭数据库的同步?有使用自定义应用程序对象在我的博客的一个例子:

If you're using ActivityUnitTestCase, you could set a custom Application object with setApplication, and have a flag in there to switch database sync on or off? There's an example of using a custom Application object on my blog:

http://www.paulbutcher.com/2011/03/mock-objects-on-android-with-borachio-part-3/

这篇关于是否有可能找出是否一个Android应用程序作为仪器测试的一部分运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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