XCUITesting 不断使我的应用程序崩溃

Posted

技术标签:

【中文标题】XCUITesting 不断使我的应用程序崩溃【英文标题】:XCUITesting continuously crashing my application 【发布时间】:2015-10-06 21:38:48 【问题描述】:

我的应用程序因以下堆栈而崩溃 -

Thread 1Queue : com.apple.main-thread (serial)
#0 0x0722dd39 in ___forwarding___ ()
#1 0x0722da0e in __forwarding_prep_0___ ()
#2 0x1782b083 in -[UITableViewCellAccessibility _accessibilityChildren] ()
#3 0x1782ccd0 in -[UITableViewCellAccessibility accessibilityElementCount] ()
#4 0x1794d241 in -[NSObject(AXPrivCategory) _accessibilityHasOrderedChildren] ()
#5 0x1795a3d2 in -[NSObject(AXPrivCategory) _accessibilityFrameForSorting] ()
#6 0x1795a4ba in -[NSObject(AXPrivCategory) accessibilityCompareGeometry:] ()
#7 0x07201532 in __36-[NSArray sortedArrayUsingSelector:]_block_invoke ()
#8 0x0720150a in __56-[NSArray sortedArrayFromRange:options:usingComparator:]_block_invoke ()
#9 0x071e7ddd in __CFSimpleMergeSort ()
#10 0x071e7e13 in __CFSimpleMergeSort ()
#11 0x071e7e2c in __CFSimpleMergeSort ()
#12 0x071e7cf3 in CFSortIndexes ()
#13 0x071f364a in -[NSArray sortedArrayFromRange:options:usingComparator:] ()
#14 0x07201454 in -[NSArray sortedArrayWithOptions:usingComparator:] ()
#15 0x072013f0 in -[NSArray sortedArrayUsingSelector:] ()
#16 0x178362df in -[UIViewAccessibility _accessibilityUserTestingChildren] ()
#17 0x1796ec58 in -[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingChildrenCount] ()
#18 0x17953483 in -[NSObject(AXPrivCategory) accessibilityAttributeValue:] ()
#19 0x1796f559 in -[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotDescendantsWithAttributes:maxDepth:maxChildren:maxArrayCount:] ()
#20 0x17970778 in -[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotWithOptions:] ()
#21 0x17951a60 in -[NSObject(AXPrivCategory) accessibilityAttributeValue:forParameter:] ()
#22 0x1793b59d in _copyParameterizedAttributeValueCallback ()
#23 0x179c9538 in _AXXMIGCopyParameterizedAttributeValue ()
#24 0x179c319a in _XCopyParameterizedAttributeValue ()
#25 0x179d24b3 in mshMIGPerform ()
#26 0x07201125 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#27 0x07201090 in __CFRunLoopDoSource1 ()
#28 0x071f6546 in __CFRunLoopRun ()
#29 0x071f5866 in CFRunLoopRunSpecific ()
#30 0x071f567b in CFRunLoopRunInMode ()
#31 0x0806a664 in GSEventRunModal ()
#32 0x0806a4a1 in GSEventRun ()
#33 0x04d52cc1 in UIApplicationMain ()
#34 0x0002dc3e in main at 
#35 0x07bbea21 in start ()

在控制台中显示以下消息 - -[UITableTextAccessibilityElement retain]:消息发送到已释放实例 0x24f4db30

我的应用程序在不进行 UI 测试的情况下运行良好。 我尝试使用记录的 UI 记录 UITest,但我仍然面临同样的崩溃。 然后我手动编写了 UI 测试,但在我的应用程序中仍然遇到同样的崩溃。

堆栈没有显示提供任何我可以调试我的应用程序的信息。

对此的任何帮助表示赞赏。

Sample Project - 使用以下步骤重现示例项目中的崩溃。

在上面的示例项目中,尝试在 TestProjectUITests.m 中运行测试 testExample。

或者,也可以尝试使用 UI Recorder 来记录 UI 测试,步骤如下

    在“收件人”字段中输入一些文本 点击汇总字段 在抄送字段上输入一些文字 点击密件抄送字段 在密件抄送字段中键入一些文本

【问题讨论】:

【参考方案1】:

如果您可以在出现此问题的地方发布一些代码或示例应用程序,那么提供一些有用的建议会更容易。如果遇到僵尸,您还可以运行僵尸工具来验证内存堆栈与对象上的每个释放/保留. 但是,控制台错误清楚地指向代码中的狡猾的 UITableView 或 UITableViewCell。您可能可以在测试期间执行的应用导航路径中找到它们。 我怀疑有保留财产,

@property(nonatomic, retain) UIView *accessibleView

在 swift 中,属性默认是强的(保留计数),

var accessibleView: UiView?

在设置 UIView 子类时定义,您可能正在使用 UIAccessibilityContainer 方法将 UI 元素公开为可访问元素。似乎属性是在 dealloc() 中释放或视图从堆栈中弹出。 如果您可以发布一些代码,事情会更清楚。

【讨论】:

添加了示例项目dropbox.com/s/iu6vnqoe32xu93e/TestProject.zip?dl=0【参考方案2】:

Apple 在 XCode 7.2 beta 1 中已修复此问题。

【讨论】:

以上是关于XCUITesting 不断使我的应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章

为啥意图使我的应用程序崩溃?

我想使我的 mfc 应用程序崩溃

释放自动释放对象不会使我的应用程序崩溃,为啥?

为啥我的 unwind segue 会使我的应用程序崩溃?

为啥我的 ListView 使我的应用程序崩溃而不是列出我的条目?

故意使我的 Windows 应用程序崩溃的最佳方法是啥?