是“猴子跑者”吗?对于测试人员直接在 Android 应用程序中准备测试用例有用吗?

发布于 2024-10-23 00:32:16 字数 308 浏览 2 评论 0原文

我已经浏览了“Monkey Runner”的以下链接 http://developer.android.com/guide/topics/testing/testing_android.html 它有这么多的Java代码。我无法理解创建测试用例的代码。是只有开发人员,还是测试人员才能彻底测试应用程序。是否还有其他通过代码创建测试用例的模式?任何人都可以向我提出同样的建议吗?

谢谢。

I have gone through the "Monkey Runner" for the following link
http://developer.android.com/guide/topics/testing/testing_android.html
It has so much Java code. I am not able to under stand the code to create test cases. Is it only for developers, or the testers to test the application thoroughly. Is there any other pattern for creating test cases through code? Can any one suggest me about the same.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

真心难拥有 2024-10-30 00:32:16

看看我的 MonkeyRunner 代码。应该比Java容易一些。更改文件保存路径,并替换电话号码。我只有 1 个问题。无法挂断电话。

#! /usr/bin/env monkeyrunner
    '''
    Created on Apr 1, 2011

    @author: sj
    '''

    import sys

    # import the MonkeyRunners modules used by this program
    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage







    def browse(d):
        d.broadcastIntent("http://www.google.com/", "ACTION_MAIN")
        #d.startActivity(component="com.android.browser/.BrowserActivity")

    def debug(device):
        print" package:%s" % device.getProperty('am.current.package')
        print" action:%s" % device.getProperty('am.current.action')
        print" comp.class:%s" % device.getProperty('am.current.comp.class')
        print" comp.package:%s" % device.getProperty('am.current.comp.package')
        print device.getProperty('display.width'), device.getProperty('display.height')

    def screenshot(d):
        MonkeyRunner.sleep(1.0)
        result = d.takeSnapshot()
        MonkeyRunner.sleep(1.0)
        result.writeToFile('/yourPath/device.png', 'png')  

    def call(d):

        d.startActivity(component="com.android.contacts/.TwelveKeyDialer")
        print "Start Activity"

        MonkeyRunner.sleep(1.0)

        d.type("+XXXXXXXX")

        # Call number.
        print "Call"
        d.touch(190, 800, 'DOWN_AND_UP');
        # not working device.press('KEYCODE_CALL', 'DOWN_AND_UP')

        print "Wait 10 sec"

        MonkeyRunner.sleep(10.0)

        # HangUp Call
        #device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')

        print "Hang Up"
        #x1 = 215
        #x2 = 230
        #y = 700
        #start = (x1,y)
        #end = (x2, y)
        #steps = 2
        #pause = 0.2
        #device.drag(start, end, pause, steps)

        d.startActivity(component="com.android.phone/.InCallScreen")
        #device.touch(230, 700, "DOWN");
        MonkeyRunner.sleep(1.0)
        #device.touch(230, 700, "UP");

        d.touch(230, 700, 'DOWN_AND_UP');
        #device.touch(270, 650, 'DOWN_AND_UP');


    def main():
        print "Start"

        # Connect to the current device returning the MonkeyDevice object
        device = MonkeyRunner.waitForConnection()

        #MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")

        if not device:
            print "Couldn't get connection"
            sys.exit()

        print "Found device"

        #call(device)
        browse(device)
        debug(device)
        screenshot(device)


        device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')

        MonkeyRunner.sleep(10.0)




    if __name__ == '__main__':
        main()

Have a look at my MonkeyRunner code. Should be easier then Java. Change path to save file, and replace phone number. I had only 1 problem. Cant Hangup a call.

#! /usr/bin/env monkeyrunner
    '''
    Created on Apr 1, 2011

    @author: sj
    '''

    import sys

    # import the MonkeyRunners modules used by this program
    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage







    def browse(d):
        d.broadcastIntent("http://www.google.com/", "ACTION_MAIN")
        #d.startActivity(component="com.android.browser/.BrowserActivity")

    def debug(device):
        print" package:%s" % device.getProperty('am.current.package')
        print" action:%s" % device.getProperty('am.current.action')
        print" comp.class:%s" % device.getProperty('am.current.comp.class')
        print" comp.package:%s" % device.getProperty('am.current.comp.package')
        print device.getProperty('display.width'), device.getProperty('display.height')

    def screenshot(d):
        MonkeyRunner.sleep(1.0)
        result = d.takeSnapshot()
        MonkeyRunner.sleep(1.0)
        result.writeToFile('/yourPath/device.png', 'png')  

    def call(d):

        d.startActivity(component="com.android.contacts/.TwelveKeyDialer")
        print "Start Activity"

        MonkeyRunner.sleep(1.0)

        d.type("+XXXXXXXX")

        # Call number.
        print "Call"
        d.touch(190, 800, 'DOWN_AND_UP');
        # not working device.press('KEYCODE_CALL', 'DOWN_AND_UP')

        print "Wait 10 sec"

        MonkeyRunner.sleep(10.0)

        # HangUp Call
        #device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')

        print "Hang Up"
        #x1 = 215
        #x2 = 230
        #y = 700
        #start = (x1,y)
        #end = (x2, y)
        #steps = 2
        #pause = 0.2
        #device.drag(start, end, pause, steps)

        d.startActivity(component="com.android.phone/.InCallScreen")
        #device.touch(230, 700, "DOWN");
        MonkeyRunner.sleep(1.0)
        #device.touch(230, 700, "UP");

        d.touch(230, 700, 'DOWN_AND_UP');
        #device.touch(270, 650, 'DOWN_AND_UP');


    def main():
        print "Start"

        # Connect to the current device returning the MonkeyDevice object
        device = MonkeyRunner.waitForConnection()

        #MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")

        if not device:
            print "Couldn't get connection"
            sys.exit()

        print "Found device"

        #call(device)
        browse(device)
        debug(device)
        screenshot(device)


        device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')

        MonkeyRunner.sleep(10.0)




    if __name__ == '__main__':
        main()
水晶透心 2024-10-30 00:32:16

我通过这个小指南学习了monkeyrunner。
http://antoine-merle.com/introduction-to- the-monkey-runner-tool-2/

您不必使用 java,而是从 python 开始。对于 ide,您可以使用 pycharm,这将为您在 python 中创建类时提供更好的开始。

截至 @Boris_Ivanov 展示的代码,这是一个好的开始,但我会删除“MonkeyImage” - 因为您没有使用它,如果需要使用,也将测试用例推送到不同的文件中会增加速度。

要说的一件事:

    Connect to the current device returning the MonkeyDevice object
    device = MonkeyRunner.waitForConnection()
    #MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")

我正在使用类似的东西,它确实一直有效:

    device = MonkeyRunner.waitForConnection(60)
    if not device:
        raise Exception('Can not connect to device')

祝你好运。

I have learned monkeyrunner via this small guide.
http://antoine-merle.com/introduction-to-the-monkey-runner-tool-2/

You do not have to use java, but to start low on python. For the ide you can use pycharm, which will give you a better start when creating classes in python.

As of the code which @Boris_Ivanov showed, this is a good start, but I would delete the "MonkeyImage" - as you are not using it also pushing the test cases into different files would add to speed if required to use.

One thing to talk about:

    Connect to the current device returning the MonkeyDevice object
    device = MonkeyRunner.waitForConnection()
    #MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")

I am using something like this and it does work all the way:

    device = MonkeyRunner.waitForConnection(60)
    if not device:
        raise Exception('Can not connect to device')

Best luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文