我正在构建通用的iPhone / iPad应用程序,并且在某些情况下,UI会有很大不同(即,在iPhone上,我们将Master / Detail范式与TableViews一起使用,而在iPad上,我们将CollectionView与包含以下内容的单元格一起使用详细信息)。>
由于接口是如此不同,它改变了构造视图控制器的单元测试的方式。在集合视图中,我们必须进行测试以确保正确构建了单元并包含所有详细信息,而在iPhone上,我们需要进行两组测试-一组用于主列表,一组用于详细屏幕。
所以我的问题是,在使用Xcode 5和XCTest框架构建的通用应用程序中,您可以针对单个单元测试用例/类来在特定的[[physical
设备上运行吗?[我在这里遇到了类似的问题-iOS Unit testing universal application-但是询问者有不同的意图并且正在使用较旧的技术。我也看到了建议对
UserInterfaceIdiom
的各个测试功能进行检查的建议,但这似乎很粗糙。理想情况下,应该有一个注释,用于指定在特定设备上运行的特定测试,或者能够为特定设备指定整个测试类别。感谢您的建议。-编辑-
@@ TommieC带我走了一条合适的路,如果是简陋的手册。我创建了两种新的测试专用方案,一种用于手机大小的设备,另一种用于平板电脑的设备。在这些方案中,我编辑了测试部分,并将其与特定于设备的测试一起添加到了核心测试中。
然后,我让詹金斯执行两个构建步骤,将适当的设备作为目标以测试特定方案。这种方法的缺点是两个构建步骤。但是,我计划拆分jenkins作业,并在2个从站上运行它,并在每个从站上连接适当的设备以并行化测试。
AFAIK这也将是Xcode Build Services友好的,因为它也基于项目中的方案工作。真是太糟糕了,XCTest并没有内置更优雅的功能,考虑到在使用新设备类型(手表/电视/吹风机/等)的情况下,缩放效果并不理想。
我正在构建通用的iPhone / iPad应用程序,并且在某些情况下,UI显着不同(即,在iPhone上,我们使用具有TableViews的Master / Detail范式,而在iPad上,我们使用...]] >
将测试分为iPhone特定测试和iPad特定测试。
现在添加专门用于iPhone或iPad的新目标(可可触摸单元测试套件)。如果您已经编写了许多通用测试,则最好还是复制当前的测试目标。
现在,通过单击导航器中的类,确保仅将iPhone特定的测试类包括在iPhone测试目标中,然后打开“实用程序”面板。您可以使用“目标成员资格”复选框设置班级所属的目标。
要对此进行扩展,可以为两个目标添加不同的方案,以更快地运行测试。
class MyTests: XCTestCase {
override class var defaultTestSuite: XCTestSuite {
let suite = XCTestSuite(forTestCaseClass: MyTests.self)
let newSuite = XCTestSuite(name: "MyTests")
for test in suite.tests {
// Name is of the form "-[MyTests test*]"
if test.name.hasSuffix("Pad]") {
// iPad only test
if UIDevice.current.userInterfaceIdiom == .pad {
newSuite.addTest(test)
}
}
else if test.name.hasSuffix("Phone]") {
// iPhone only test
if UIDevice.current.userInterfaceIdiom == .phone {
newSuite.addTest(test)
}
}
else {
// Can run on both devices
newSuite.addTest(test)
}
}
return newSuite
}
func testAll() { // All devices test }
func testOnlyPad() { // iPad only test }
func testOnlyPhone() { // iPhone only test }
}
将测试分为iPhone特定测试和iPad特定测试。
class MyTests: XCTestCase {
override class var defaultTestSuite: XCTestSuite {
let suite = XCTestSuite(forTestCaseClass: MyTests.self)
let newSuite = XCTestSuite(name: "MyTests")
for test in suite.tests {
// Name is of the form "-[MyTests test*]"
if test.name.hasSuffix("Pad]") {
// iPad only test
if UIDevice.current.userInterfaceIdiom == .pad {
newSuite.addTest(test)
}
}
else if test.name.hasSuffix("Phone]") {
// iPhone only test
if UIDevice.current.userInterfaceIdiom == .phone {
newSuite.addTest(test)
}
}
else {
// Can run on both devices
newSuite.addTest(test)
}
}
return newSuite
}
func testAll() { // All devices test }
func testOnlyPad() { // iPad only test }
func testOnlyPhone() { // iPhone only test }
}