Tag: xctest

我如何从SenTestingKit / OCUnit迁移到XCTest?

我正在将我的项目从Xcode 4.6.3迁移到Xcode 5.0.2。 该项目的unit testing是用SenTestingKit / OCUnit开发的。 现在,当我在Xcode 5中运行testing时,从RunUnitTests脚本中得到一个错误,告诉我这一点 RunUnitTests已经过时。 Xcode 5发行说明中可能与此有关: SenTestingKit和OCUnit已弃用。 使用移动器移动到XCTest。 不幸的是,我还没有find更多关于这个神秘的“移民”的信息。 可能我的google-fu缺乏[再次],所以我的主要问题是:如何将unit testing从SenTestingKit / OCUnit迁移到新的XCTest(带或不带“migrator”)? 第二个问题,如果迁移是一个复杂的业务:是否有可能让Xcode 5运行仍然基于SenTestingKit / OCUnit的unit testing? 毕竟这些只是被弃用,所以他们仍然应该在周围和function。

XCTAssertEqual错误:(“3”)不等于(“3”)

NSMutableArray *arr = [NSMutableArray array]; [arr addObject:@"1"]; [arr addObject:@"2"]; [arr addObject:@"3"]; // This statement is fine. XCTAssertTrue(arr.count == 3, @"Wrong array size."); // This assertion fails with an error: ((arr.count) equal to (3)) failed: ("3") is not equal to ("3") XCTAssertEqual(arr.count, 3, @"Wrong array size."); 我对XCTAssertEqual有什么不了解? 为什么最后的断言失败?

在Xcode 6中进行XCTest和asynchronoustesting

所以苹果在Xcode 6的发布logging中说,我们现在可以直接使用XCTest进行asynchronoustesting。 任何人都知道如何使用Xcode 6 Beta 3(使用Objective-C或Swift)? 我不想要已知的信号量方法,而是新的苹果方式。 我search了发布的音符和更多,但我什么也没find。 XCTest标题也不是很明确。

如何让应用程序知道它的运行unit testing纯Swift项目?

在XCode 6.1中运行testing时一件令人讨厌的事情是,整个应用程序必须运行并启动其storyboard和root viewController。 在我的应用程序中运行一些服务器调用来获取API数据。 但是,我不希望应用程序在运行testing时执行此操作。 预处理器的macros不见了,对于我的项目来说,最好的办法是启动运行testing,而不是普通的启动。 我用CMD + U和机器人正常运行它们。 伪代码将是: // Appdelegate.swift if runningTests() { return } else { // do ordinary api calls }

XCTestCase的setUp方法的目的是什么?

根据XCTestCase有关setUp的默认模板中的XCTestCase : Put setup code here; it will be run once, before the first test case. 但是,在XCTestCase.h ,上面的setUp注释不同: Setup method called before the invocation of each test method in the class. 为了确认实际行为,我在setUp放置了一个NSLog来计算它被调用的次数: static int count = 0; – (void)setUp { [super setUp]; count++; NSLog(@"Call Count = %d", count); } 这导致在每个testing方法之前调用setUp方法(确认对XCTestCase.h的评论)。 我想使用setUp方法创build一次testing/模拟对象(例如,设置一个核心数据testing栈)。 一遍又一遍地创build这些将是处理器密集型,可能非常缓慢。 所以, 1)实际上打算使用的setUp是什么? 开发人员不是一遍又一遍地创build对象吗? […]

有没有办法在Xcode 7中的Swift XCTest UI中的testing之间重置应用程序?

在XCTest中是否有API调用,我可以放入setUP()或tearDown()来重置testing之间的应用程序? 我查看了XCUIApplication的点语法,我只看到了.launch() OR有没有办法在Swift中调用shell脚本? 然后我可以调用xcrun中间的testing方法来重置模拟器。

Xcode 5说testing失败,但显示绿色的选中标记

我已经在Xcode 5的新XCTest框架中写了几个unit testing。 testing似乎大部分时间顺利通过,但我遇到了一个奇怪的行为,如果我连续运行testing足够多的时间,最终我会得到一个“testing失败”的消息,控制台将显示Program ended with exit code 0 ,但在所有testing旁边都有绿色的复选标记。 这里怎么了?

Xcodeunit testing用Cocoapods

在过去的几天里,我一直在用这种方式将我的头撞在墙上,但是尽pipe有多个Google / SO / Githubsearch,我找不到解决我遇到的问题的办法! 我所要做的就是为我的应用程序创build一些使用Firebase窗格的unit testing。 我正在使用Xcode 7.3.1和Cocoapods 1.0.1。 更新:问题仍然与Xcode 8.0 有了这个podfile: platform :ios, '9.0' use_frameworks! inhibit_all_warnings! target 'MyApp' do pod 'Firebase' pod 'Firebase/Auth' pod 'Firebase/Database' pod 'Firebase/Storage' target 'MyAppTests' do inherit! :search_paths end end 在我的XCTest类中, 缺less必需的模块“Firebase” 错误@ @testable import MyApp 或者用这个podfile: platform :ios, '9.0' use_frameworks! inhibit_all_warnings! def common_pods pod 'SwiftyTimer' pod 'Firebase' pod […]

Xcode 6编辑器不能识别unit testing

我有一个问题,Xcode IDE 6不能正确检测我的swiftunit testing用例。 当我运行unit testing时,所有的testing都被执行了。 但是在编辑IDE的时候,unit testing是不能识别的。 我必须运行整个unit testing套件才能运行单个testing。 我无法弄清楚如何避免这个故障。

XCTAssertEqual无法比较两个string值?

我添加了一个简单的unit testing来testing我的string扩展。 但是失败了。 我在这里做错了什么? 从我所知道的XCTAssertEqual是testing的价值,而不是对象本身? 第三行btw,表示string是平等的,但XCTAssertEqual说,他们不是。 – (void) testInitialsFromFullname { NSString *firstNickName = @"Mike Kain"; NSString *expectedResult = @"MK"; NSLog(@"Equal:%@", [[firstNickName initialsFromString] isEqualToString:expectedResult] ? @"YES" : @"NO"); XCTAssertEqual(expectedResult, [firstNickName initialsFromString], @"Strings are not equal %@ %@", expectedResult, [firstNickName initialsFromString]); }