小编lac*_*ton的帖子

Android:为测试目的注入假相机预览

我正在写一些在物理Android设备上运行的黑盒验收测试.被测应用程序(AUT)依赖于相机的预览.具体来说,它使用setOneShotPreviewCallbackandroid.hardware.Camera类的方法.我正在寻找一种方法来注入假预览图片来测试应用程序的行为.

我以为我可以通过让测试代码调用AUT的PreviewCallback对象来欺骗Camera对象,但不幸的是,实例变量mPreviewCallback对于Camera对象是私有的,因此我的测试代码无法获得对该PreviewCallback对象的引用.

我想到的另一种方法是向Message相机发送一个EventHandler,但该字段mEventHandler是私有的,因此测试代码无法获得对Handler的引用.

android android-camera android-testing

9
推荐指数
1
解决办法
1万
查看次数

Python 中的 Try/Except:如何避免重复?

我有一个类,可以将 API 引发的低级异常转换为高级异常。该类充满了复杂、重复的错误处理逻辑。我正在寻找减少这种重复的Pythonic 方法。

这是一个人为的例子。

class ApiWrapperException(Exception):
  pass

class ApiWrapper(object):

  def __init__(self, api):
    self._api = api

  def do_one_thing(self):
    print 'do_one_thing stuff before API call'
    try:
      self._api.do_one_thing()
    except ApiException:
      print 'ApiWrapper caught an ApiException. Doing complicated error handling logic. Raising a different exception.'
      raise ApiWrapperException
    print 'do_one_thing stuff after API call'

  def do_another_thing(self):
    print 'do_another_thing stuff before API call'
    try:
      self._api.do_another_thing()
    except ApiException:
      print 'ApiWrapper caught an ApiException. Doing complicated error handling logic. Raising a different exception.'
      raise ApiWrapperException
    print 'do_another_thing …
Run Code Online (Sandbox Code Playgroud)

python contextmanager python-decorators

8
推荐指数
1
解决办法
1704
查看次数

Android:以编程方式删除或禁用Samsung Galaxy S2设备上的锁定屏幕

问题我的Android自动化测试不可靠,因为测试的活动有时会运行并且有时会暂停.

原因如果我的Android设备(三星Galaxy S2)启用了锁屏,则所有活动都会立即进入暂停模式.

如何在我的测试运行时以编程方式禁用锁定屏幕?

这是我尝试过的,根本没有产生任何结果(即,锁定屏幕仍处于活动状态并暂停我的活动).

  • 添加android.permission.DISABLE_KEYGUARD权限并KeyguardLock.disableKeyguard()按照android doc中的说明使用.

  • 设置窗口标志:FLAG_SHOW_WHEN_LOCKED,FLAG_TURN_SCREEN_ON,FLAG_DISMISS_KEYGUARD.

  • 使用WakeLock.acquire()PowerManager.FULL_WAKE_LOCK,PowerManager.ACQUIRE_CAUSES_WAKEUP,PowerManager.ON_AFTER_RELEASEPowerManager.SCREEN_BRIGHT_WAKE_LOCK参数.

  • adb shell input keyevent 82

android android-activity

3
推荐指数
3
解决办法
2万
查看次数