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

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

问题描述

是否对应用程序进行运行时检查,以查明它是否作为工具测试的一部分运行?

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

背景:我们的应用程序在启动时执行数据库同步.但这仅应在定期启动时发生.它尤其会干扰测试数据库同步的测试.不足为奇.

Background: Our application performs a database sync when starting. But that should happen only when started regularly. It especially interferes with the instrumentation tests testing the db sync. Not surprisingly.

使用所有其他测试,这只是浪费CPU周期.

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

推荐答案

如果使用的是ActivityUnitTestCase,则可以使用setApplication设置自定义Application对象,并在其中设置一个标志来打开或关闭数据库同步?在我的博客上有一个使用自定义Application对象的示例:

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天全站免登陆