OCUnit测试嵌入式框架

d11*_*wtq 5 xcode cocoa objective-c ocunit gh-unit

更新:我最终放弃并将GHUnit添加到我的项目中.我在几分钟内就开始使用GHUnit.

更新:您可以在此处下载Xcode项目:http://github.com/d11wtq/Cioccolata

我已经为我的Xcode项目添加了一个单元测试目标,但它在构建时找不到我的框架,说:

Test.octest could not be loaded because a link error occurred. It is likely that dyld cannot locate a framework framework or library that the the test bundle was linked against, possibly because the framework or library had an incorrect install path at link time.

我的框架(主项目目标)旨在嵌入,因此具有安装路径@executable_path/../Frameworks.

我已将框架标记为测试目标的直接依赖关系,并将其添加到"Link Binary with Libraries"构建阶段.

另外,我添加了"复制文件"的第一步(在它构建了依赖项之后),它只是将框架复制到单元测试包的Frameworks目录中.

有人有这方面的经验吗?我不确定我错过了什么.

编辑| 我很确定我不应该,因为框架不可执行,但我没有设置"测试主机"和"捆绑加载器".这应该(据我的理解)一切正常,因为测试包与框架链接并将像任何其他包一样加载它.

编辑| 我想我差不多了.我阅读了以下文章,该文章规定使用@rpath而不是@executable_path.

http://www.dribin.org/dave/blog/archives/2009/11/15/rpath/

在这种情况下,它非常有意义,因为OCUnit测试包不是可执行文件,它是一个普通的旧包,所以@executable_path不兼容.所以现在我的框架将其安装目录设置为@rpath,并且Test目标将其运行时搜索路径(rpath)定义为构建目录.这节省了我不得不将框架复制到测试包中,这意味着整个生成的框架本质上更灵活,因为它可以在任何地方生活.

现在,我也意识到我应该在Test目标上设置Bundle Loader,所以现在将其设置为框架二进制文件的路径.

我可以构建测试目标,我可以从框架中#import类,没有错误.但是一旦我尝试从框架中实例化一个类,我就会收到以下错误:

/Developer/Tools/RunPlatformUnitTests.include:412: note: Started tests for architectures 'i386' /Developer/Tools/RunPlatformUnitTests.include:419: note: Running tests for architecture 'i386' (GC OFF) objc[50676]: GC: forcing GC OFF because OBJC_DISABLE_GC is set Test Suite '/Users/chris/Projects/Mac/Cioccolata/build/Debug/Test.octest(Tests)' started at 2010-05-21 12:53:00 +1000 Test Suite 'CTRequestTest' started at 2010-05-21 12:53:00 +1000 Test Case '-[CTRequestTest testNothing]' started. /Developer/Tools/RunPlatformUnitTests.include: line 415: 50676 Bus error "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}" /Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Developer/Tools/otest' exited abnormally with code 138 (it may have crashed). Command /bin/sh failed with exit code 1

我的测试方法只是分配并随后发布我创建的HelloWorld类来帮助调试此设置:

- (void)testNothing {
    CTHelloWorld *h = [[CTHelloWorld alloc] init];
    [h release];
}
Run Code Online (Sandbox Code Playgroud)

如果我用STAssertTrue(YES, @"Testing nothing");错误消除这些代码行,即使该类仍在导入.

d11*_*wtq 4

由于没有其他人回答这个问题,我最后想说的是,SenTestingKit 的设置的复杂性(和丑陋)确实让我印象深刻,无法满足我的需求。我强烈推荐 GHUnit,它在 UI 中运行(如果您愿意,也可以在命令行上运行),并且支持开箱即用地使用 gdb。我花了几分钟的时间下载并在我的项目中使用 GHUnit。

也很漂亮啊 Apple 应该将其与 Xcode 一起提供,而不是 SenTestingKit 恕我直言。