【发布时间】:2010-11-08 17:00:27
【问题描述】:
我一直在关注 Apple 关于为 iPhone 编写单元测试的文档,并且开箱即用,该例程似乎不起作用。我不确定我是否了解单元测试将在哪里获得对应用程序委托的引用。
我的依赖如下: My_Program_target -> UnitTesting_target -> UnitTests_bundle
下面的代码 sn-p 是断言失败的地方。我对 CPPUNIT 非常熟悉,但我无法理解它是如何跨越的。
- (void) testAppDelegate {
id yourApplicationDelegate = [[UIApplication sharedApplication] delegate];
STAssertNotNil(yourApplicationDelegate, @"UIAppliation failed to find the AppDelegate");
}
另外:
我已经决定在我的方法中进行逻辑测试。我正在尝试读取一个 XML 文件,但我没有运气解决该捆绑包,这将为我提供访问文件的路径。我尝试粘贴 allBundles 的路径输出,但该路径似乎也不起作用。下面是我在测试中执行的内容(你可以看到我用来输出包路径的调试语句):
NSLog(@"BundlePaths: %@", [NSBundle allBundles]);
NSString * path = [[NSBundle bundleWithPath:@"$(TARGET_BUILD_DIR)"] pathForResource:@"SimpleTestList" ofType:@"plist"];
STAssertNotNil(path, @"Bundle Location couldn't find the file specified");
基本上,路径上的断言不成功,但我不确定要为路径或目录放置什么来引用我告诉我复制包资源的 unitTest 包。调用 [NSBundle mainBundle] 也不起作用。
【问题讨论】:
-
在 Gary 的解决方案的基础上,我提出了以下Xcode: TEST vs DEBUG preprocessor macros。
标签: unit-testing xcode resources ocunit