XCode UITests 无法 运行 并出现意外退出错误(仅限机器人)

XCode UITests fail to run with Unexpected Exit Error (Bot only)

我的 XCode UI 测试无法 运行 使用机器人,即使只是 运行 使用默认的测试示例 class (没有代码) .相反,我收到一个错误:

Testing failed: Test target UIBotTest encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted) ** TEST FAILED **

在机器人之外,我的测试 运行 正在通过并且没有出现此类故障。 我尝试实施的一种解决方案是利用系统警报处理程序在应用程序首次启动时处理通知权限警报,如下所示:

XCUIApplication *app = [[XCUIApplication alloc]init];
    [self addUIInterruptionMonitorWithDescription:@"Notification Handler" handler:^BOOL(XCUIElement * _Nonnull interruptingElement) {

    if ([interruptingElement.buttons[@"OK"] exists])
    {
        [interruptingElement.buttons[@"OK"] tap];
        [app tap];
        return true;
    }
    return false;
}];

我尝试在我的 setUp 和 testExample 函数中实现它,并且再次 运行 在模拟器和物理设备上没问题,但是在机器人上失败并出现同样的错误。

有什么想法吗?

事实证明,系统警报是导致问题的原因——无论出于何种原因,我的 UIInterruptionMoniter 都没有 运行 正确地安装在机器人上。在测试期间禁用通知权限警报解决了我的问题。