簡體   English   中英

iOS Swift UI 測試 (XCUITests) 穩定性問題 - 快速通道掃描

[英]iOS Swift UI Tests (XCUITests) stability problem - fastlane scan

在通過 fastlane (scan) 運行 iOS 測試期間,測試的穩定性存在隨機問題。 日志中可見的錯誤:

Lost connection to the application (pid XXXX).
<unknown>:0

有誰知道與應用程序失去連接的可能原因是什么?

我的測試是在類中實現的,每個類都繼承了 BaseTest 類,應用程序以下列方式啟動:

import XCTest

class BaseTest: XCTestCase {

    let app = XCUIApplication()
    ...

    override func setUp() {
        continueAfterFailure = false
        app.launch()
        ...
    }

    override func tearDown() {
        super.tearDown()
        let screenshot = XCUIScreen.main.screenshot()
        let fullScreenshotAttachment = XCTAttachment(screenshot: screenshot)
        fullScreenshotAttachment.lifetime = .deleteOnSuccess
        add(fullScreenshotAttachment)
        app.terminate()
    }

    ...
}

還實現了 Page Object 類,每個類都繼承了 BaseScreen:

import XCTest

class BaseScreen {

    let app: XCUIApplication = XCUIApplication()
}

extension BaseScreen {
    func findAll(_ type: XCUIElement.ElementType) -> XCUIElementQuery {
        return app.descendants(matching: type)
    }
}

測試通過 fastlane 運行,如下所示:

lane :ui_tests do

    # Performing UI Tests
    scan(
      clean: true,
      reinstall_app: true,
      app_identifier: "XXX",
      workspace: workspace,
      scheme: "uiTests",
      devices: devicesUITests,
      code_coverage: true,
      open_report: false,
      output_style: "rspec",
      output_types: "html",
      output_directory: "./build/DerivedData/test_output",
      result_bundle: "true",
      buildlog_path: "./XXX",
      xcargs: "OTHER_SWIFT_FLAGS=\"-Xfrontend -debug-time-function-bodies\" SWIFT_OPTIMIZATION_LEVEL=\"-Owholemodule\"",
      derived_data_path: "./build/DerivedData"
      )

      puts("Generating Test Report ...")
      sh('xchtmlreport -r ../build/DerivedData/test_output')
      puts("Test Report Successfully generated")
  end

我也在使用 UIInterruptionMonitor 進行警報,這也可能是相關的。

編輯: StandardAndStandardError.txt 的末尾有以下片段:

2019-03-15 12:23:49.511 XXX[35711:8931440] *** Accessing the keyManager while not available yet
2019-03-15 12:23:49.511 XXX[35711:8931440] *** Accessing the keyManager while not available yet
2019-03-15 12:23:50.065 XXX[35711:8931461] Cannot find executable for CFBundle 0x7fd7f74336e0 </.../Library/Developer/CoreSimulator/Devices/.../data/Containers/Bundle/Application/.../XXX.app/Frameworks/DJISDK.framework/DJIFlySafe.bundle> (not loaded)
2019-03-15 12:23:50.073 XXX[35711:8931465] Cannot find executable for CFBundle 0x7fd7f75015d0 </.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/Frameworks/DJISDK.framework/SDKSharedLib.bundle> (not loaded)
CoreData: annotation:  Failed to load optimized model at path '/.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
CoreData: annotation:  Failed to load optimized model at path '/.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
CoreData: annotation:  Failed to load optimized model at path '/.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
xxx(35711,0x7000060f9000) malloc: Heap corruption detected, free list is damaged at 0x6000009754a0
*** Incorrect guard value: 4416955976
xxx(35711,0x7000060f9000) malloc: *** set a breakpoint in malloc_error_break to debug

好吧,記得使用removeUIInterrutpionMonitor方法! 問題的原因是聲明了很多 UIInterruptionMonitor 對象,並且線程有問題。 添加刪除 UIInterruptionMonitor 對象后,問題消失了。 :)

我上周遇到了類似的問題。 我認為在我的構建機器上更新到最新版本的 fastlane 和 Xcode 解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM