gpt4 book ai didi

ios - 谷歌地图打破业务逻辑单元测试

转载 作者:行者123 更新时间:2023-11-30 11:40:54 26 4
gpt4 key购买 nike

我正在编写一个使用 GoogleMaps 的 iOS 应用程序。我编写了一些单元测试来测试单独的业务逻辑模块。它们看起来像这样:

func testIfStationsExistNearPoint1() {
let comMangager = CommunicationManager()
comMangager.getListOfStations(coordinates: Coordinates(longitude: Constants.Point1CoordinateLongitude, latitude: Constants.Point1CoordinateLatitude), distance: 50, completion: { (json) in
if (json != nil) {
let stations = StationWrapper.sharedStationWrapper.jsonToStations(json: json!)

assert(stations.count > 0, String(format:"%ld stations", stations.count))
}
else {
XCTFail("json is nil")
}
}) { (error) in
XCTFail(String(format:"List of stations returned error: %@", error))
}
}

请注意,这些单元测试与 UI 完全分离(使用 GoogleMaps 的地方。坐标是自定义类,而不是 GoogleMaps CLLocationCooperative2D)。

另请注意,该应用程序本身运行正常。我 100% 确定,在主应用程序中,所有与 map 绘制相关的代码都在主线程中调用。

然而,在尝试任何我的单元测试时,不知怎的,我收到了这个错误:

com.google.Maps.LabelingBehavior (15): -[UIApplication applicationState] must be used from main thread only

当我在此单元测试的第一行设置断点时,它甚至没有被命中。模拟器和真实设备都是一样的。

我想知道,这怎么可能,因为我在单元测试中没有在任何地方使用 Google map ?我尝试过搜索类似的案例,但没有找到,这是相关的单元测试。

你知道这里出了什么问题吗,因为我感觉完全被困住了?

最佳答案

XCode 在执行单元测试之前启动您的应用程序。

所以这个错误是在 Xcode 开始执行单元测试之前由您的应用程序产生的。这就是为什么你在测试开始时的断点没有被击中的原因。

放置异常断点应该可以引导您找到问题的根源。

关于ios - 谷歌地图打破业务逻辑单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49299595/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com