简体   繁体   English

Android功能测试; 将地理位置发送到模拟器

[英]Android functional test; send geo location to emulator

Our android application is getting fairly big and we would like to use functional tests for our application to prevent regression. 我们的android应用程序变得相当大,我们希望为我们的应用程序使用功能测试来防止回归。 We are looking in to options to achieve this. 我们正在寻找实现这一目标的方案。

We make use of geo locations, so now we test the app by entering lat/long in DDMS. 我们使用地理位置,所以现在我们通过在DDMS中输入lat / long来测试应用程序。 If we want to test this, it should be possible to set these geo locations programmatically. 如果我们要测试它,应该可以以编程方式设置这些地理位置。

Is there a framework that we can use to functional test our android app and also send these updates to our emulator? 是否有一个框架,我们可以用来功能测试我们的Android应用程序,并将这些更新发送到我们的模拟器?

If you compile in Eclipse, you can fake the lat/lon in the android emulator: 如果你在Eclipse中编译,你可以伪造android模拟器中的lat / lon:

  • Windows > Open perspective > Other. Windows>打开透视图>其他。
  • Choose DDMS 选择DDMS
  • Search Emulator control tab 搜索模拟器控制选项卡
  • Use the location control to send Latitude and Longitude whenever you want. 使用位置控件可以随时发送纬度和经度。

I am facing the same problem. 我面临同样的问题。 While this solution is not built into robotium, you should be able to make it into a utility that can be used in your unit tests. 虽然此解决方案未内置于robotium中,但您应该能够将其变为可用于单元测试的实用程序。

Unit Testing Location Service 单元测试位置服务

If you use monkeyrunner, then you might use this function: 如果你使用monkeyrunner,那么你可以使用这个函数:

def telnet(host, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(2)

    # connect to remote host
    try :
        s.connect((host, port))
    except :
        print 'Unable to connect'
        sys.exit()

    print 'Connected to remote host'
    return s

def geo_fix(port, lat, lng):
    print "setting gps to " + str(lat) + "," + str(lng)
    socket = telnet("localhost", port)
    socket.send("geo fix " + str(lng) + " " + str(lat) + "\n")
    socket.send("exit\n")
    socket.close()

geo_fix(5554, 32.0878802, 34.797246)

I couldn't find a way to get the emulator's port from the MonkeyDevice, so I manually pass the port, but would be nicer if we could figure it out from the device object 我找不到从MonkeyDevice获取模拟器端口的方法,所以我手动传递端口,但如果我们可以从设备对象中弄清楚它会更好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM