我正在尝试按照描述实施应用程序测试 此处。到目前为止,一切都很好,但我无法测试,例如,使用核心位置测试设备的位置。我已将适当的框架添加到目标,并已启动位置更新,但我不知道如何等待加载位置,测试套件在第二个线程完成之前结束。请帮助我找到一种方法来测试此类事情。
I'm trying to implement Application Tests as described here. So far, so good, but i fail to test, for instance, the location of the device using Core Location. I have added the appropriate Framework to the Target, and have initiated the update of location, but i have no clue of how to wait for the location to be loaded, the test suite just ends before the second thread finish. Please help me to find a way to test this sort of things.
发布评论
评论(1)
如果您依赖于
CLLocationManager
,您可以在CLLocationManagerDelegate
中实现这两个委托方法:然后设置
CLLocationmanager
委托并告诉它>开始更新位置
。如果您得到didUpdateLocation
(oldLocation
设置为 nil),则意味着您现在有了一个位置,并且可以认为测试成功(确保关闭更新)。如果您收到另一份,则存在位置管理器错误。如果您依赖 MapKit 并使用
MKMapView
的用户位置更新机制,请查看我对 这个问题并实现观察者部分(observeValueForKeyPath
),以便在地图出现时收到通知位置(成功)或实现 MKMapViewDelegate 的mapViewDidFailLoadingMap
以在出现错误时收到通知。If you're relying on
CLLocationManager
you can implement these two delegate methods inCLLocationManagerDelegate
:Then you set the
CLLocationmanager
delegate and tell it tostartUpdatingLocation
. If you getdidUpdateLocation
(witholdLocation
set to nil) it means you now have a location and you can consider the test a success (make sure you turn off updating). If you get the other one there was a location-manager error.If you're relying on MapKit and are using
MKMapView
's user-location update mechanism, then take a look at my response to this question and implement the observer section (observeValueForKeyPath
) to be notified when the map has a location (success) or implement MKMapViewDelegate'smapViewDidFailLoadingMap
to be notified if there was an error.