问题描述
大家好,
我想从我的MonkeyRunner脚本运行我的测试仪器之一。可惜我不能得到它的工作。我已经打过电话MonkeyDevice.instrument带有参数的不同变化,但没有运气。
HI guys,I'm trying to run one of my test instrumentation from my MonkeyRunner script. Unfortunately I can't get it to work. I've tried calling MonkeyDevice.instrument with different variations of the parameters but had no luck.
我试过
设备= MonkeyRunner.waitForConnection()
device.instrument(android.test.InstrumentationTestRunner)
device.instrument(com.myTestPackage.myTestClass)
device.instrument(com.myTestPackage / .myTestClass)
device.instrument(myTestClass)
device = MonkeyRunner.waitForConnection()device.instrument("android.test.InstrumentationTestRunner")device.instrument("com.myTestPackage.myTestClass")device.instrument("com.myTestPackage/.myTestClass")device.instrument("myTestClass")
这些都不扔错的,但他们没有任何运行测试。我可以通过开发工具运行我的仪器或者虽然Android的JUnit测试,所以我知道它的工作原理。
None of these throw and error but they don't run the test either. I can run my instrumentation via Dev Tools or though Android Junit Test so I know it works.
所以,有人可以告诉我正确使用这种方法吗?谢谢你。
So can someone tell me the correct to use this method? Thanks.
推荐答案
您可能正在使用错误的论点。这个脚本,我命名为 instrumentation.mr
,可以帮助你使用正确的。
使用你的目标包名调用它。
You are probably using wrong arguments. This script, which I named instrumentation.mr
, helps you to use the right ones.Invoke it using you target package name.
#! /usr/bin/env monkeyrunner
import sys
from com.android.monkeyrunner import MonkeyRunner
PLI = 'pm list instrumentation'
def usage():
print >>sys.stderr, "usage: intrumentation.mr target-package"
sys.exit(1)
def main():
if len(sys.argv) != 2:
usage()
pkg = sys.argv[1]
print "waiting for connection..."
device = MonkeyRunner.waitForConnection()
print "running istrumentation for %s" % pkg
for (i, t) in map(lambda l: l.split(), device.shell(PLI).splitlines()):
if t == '(target=%s)' % pkg:
print device.instrument(i.split(':')[1], { 'wait':True })['stream']
return
print >>sys.stderr, "ERROR: instrumentation for %s not found" % pkg
if __name__ == '__main__':
main()
例如:
$ instrumentation.mr com.example.aatg.tc
打印:
waiting for connection...
running istrumentation for com.example.aatg.tc
Test results for InstrumentationTestRunner=...............................
Time: 39.932
OK (31 tests)
这篇关于如何使用MonkeyDevice.instrument?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!