在UITesting期间导致内存警告和崩溃的背景图像

时间:2015-12-11 17:29:05

标签: ios swift xcode-ui-testing

我有一个简单的UITest,可以在工具栏上点击一个项目100次,在没有背景图像的情况下运行测试,但是当我添加背景图像时,我会收到内存警告,然后测试失败。我已经尝试了许多用于显示图像的解决方案,大多数都会导致相同的结果,内存警告随后发生崩溃。我有一个图像集,包括三个大小为3X的png图像:2304 X 3072,2X:1536 X 2048和1X:768 X 1024,根据苹果文档。如何添加背景图像以免造成内存问题。

UITesting Code:

func testJustNumberOfRolls() {
    let app = XCUIApplication()
    for _ in 1...100 {
        app.toolbars.buttons["Tip2"].tap()
    }
}

ViewController:

class TestVC: UIViewController {    

    override func viewDidLoad() {
        super.viewDidLoad()
        if let image = UIImage(named: "feltSized") {
            self.view.backgroundColor = UIColor(patternImage: image)
        }
    }
}

测试日志:

11:10:49.317 XCTRunner[6768:2874277] -[TestingUIActual 

testJustNumberOfRolls] started activity <XCActivityRecord: 0x1314a5ab0> 2015-12-11 17:10:49 +0000: Wait for app to idle
11:10:49.528 XCTRunner[6768:2874277] Waiting for app quiescence...
11:10:49.529 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:49.529 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:49.530 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:49.531 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:49.535 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.536 XCTRunner[6768:2874320] Got animations reply.
11:10:49.536 XCTRunner[6768:2874320] Animations are not active.
11:10:49.537 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.537 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:49.538 XCTRunner[6768:2874320] Got event loop idle reply.
11:10:49.539 XCTRunner[6768:2874320] Event loop is idle.
11:10:49.538 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:49.540 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:49.541 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:49.542 XCTRunner[6768:2874277] App has quiesced.
11:10:49.542 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1314a5ab0> 2015-12-11 17:10:49 +0000: Wait for app to idle (0.225394s)
11:10:49.550 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1314a2970> 2015-12-11 17:10:49 +0000: Find the "Tip2" Button (0.298589s)
11:10:49.553 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x1314abf80> 2015-12-11 17:10:49 +0000: Synthesize event
11:10:49.966 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.967 XCTRunner[6768:2874320] Got event completion.
11:10:49.969 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1314abf80> 2015-12-11 17:10:49 +0000: Synthesize event (0.416638s)
11:10:49.973 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.988 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x1315415e0> 2015-12-11 17:10:49 +0000: Wait for app to idle
11:10:50.197 XCTRunner[6768:2874277] Waiting for app quiescence...
11:10:50.198 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.198 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.199 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.200 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.204 XCTRunner[6768:2874358] Got AX notification 4002
11:10:50.204 XCTRunner[6768:2874358] Got event loop idle reply.
11:10:50.205 XCTRunner[6768:2874358] Event loop is idle.
11:10:50.205 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.206 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.437 XCTRunner[6768:2874358] Got AX notification 4002
11:10:50.438 XCTRunner[6768:2874358] Got animations reply.
11:10:50.442 XCTRunner[6768:2874358] Animations are not active.
11:10:50.443 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.444 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.446 XCTRunner[6768:2874277] App has quiesced.
11:10:50.447 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1315415e0> 2015-12-11 17:10:49 +0000: Wait for app to idle (0.459272s)
11:10:50.460 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x13149e5f0> 2015-12-11 17:10:49 +0000: Tap "Tip2" Button (1.4335s)
11:10:50.464 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x1314af0f0> 2015-12-11 17:10:50 +0000: Tap "Tip2" Button
11:10:50.466 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x131544810> 2015-12-11 17:10:50 +0000: Wait for app to idle
11:10:50.669 XCTRunner[6768:2874277] Waiting for app quiescence...
11:10:50.669 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.670 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.670 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.671 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.676 XCTRunner[6768:2874356] Got AX notification 4002
11:10:50.676 XCTRunner[6768:2874356] Got animations reply.
11:10:50.677 XCTRunner[6768:2874356] Animations are not active.
11:10:50.677 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.677 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.679 XCTRunner[6768:2874320] Got AX notification 4002
11:10:50.679 XCTRunner[6768:2874320] Got event loop idle reply.
11:10:50.680 XCTRunner[6768:2874320] Event loop is idle.
11:10:50.680 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.681 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.682 XCTRunner[6768:2874277] App has quiesced.
11:10:50.682 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x131544810> 2015-12-11 17:10:50 +0000: Wait for app to idle (0.216641s)
11:10:50.718 Xcode[1265:207640] Test operation failure: Lost connection to test manager service.
11:10:50.719 Xcode[1265:207640] _finishWithError:Error Domain=IDETestOperationsObserverErrorDomain Code=4 "Lost connection to test manager service." UserInfo={NSLocalizedDescription=Lost connection to test manager service.} didCancel: 1

1 个答案:

答案 0 :(得分:0)

更新:我尝试不显示任何图像,这似乎更好。错误显示为'与测试管理器服务的连接丢失'。

此时我已经重构了我的应用程序以避免长动画以避免我的测试需要超时,然后重新编码应用程序以隐藏所有图像和背景颜色。即使这样,错误仍然会出现,尽管测试可以运行更长时间。

我能够使用背景图案和按钮在一个全新的应用程序上进行复制,即使在运行测试超过几分钟时也会导致错误,这就是全新的应用程序。所以还有什么可以做的,希望很快就会解决。