我有一个 Xcode 静态库项目,如何向其中添加测试目标以便可以在那里运行它? (而不是在链接到它的项目中。)
我希望能够在库目标中测试库代码,这样我就不必切换到单独的项目来运行它。
我了解如何添加目标,但不确定如何将其设置为像“命令行工具”项目模板一样运行。我尝试添加一个新的“Shell Tool”目标,但我不知道如何使其像目标一样运行。我必须向该目标添加哪些构建设置?我需要什么文件(main.m?)来启动它?
编辑(添加了我在下面的评论,希望使问题更容易回答。)
我的库有两个目标,一个用于 iOS,一个用于 MacOS。到目前为止我只将它包含在一个 iOS 项目中,所以这就是我目前想要使用的项目。我尝试添加 Cocoa Touch 单元测试捆绑包目标,但我的构建失败,并且命令 /bin/sh/ 失败,退出代码为 1,并且架构“i386”测试失败(GC 关闭)。我不认为我想在 i386 上运行(至少不想测试我的 iOS 目标)并且我在目标设置中找不到任何显示 i386 的内容。
我看到该项目的活动架构是 i386(在“项目”>“设置活动架构”菜单中),但它不允许我在那里更改它。我的 TestApp 目标将标准(armv6)作为体系结构集,我尝试搜索设置,但没有任何内容包含 i386。我该如何改变这一点?
I want to be able to test library code in the library target so I don't have to switch over to a separate project to run it.
I see how to add a target, but I'm not sure how to set it up to run like the "Command Line Tool" project template does. I tried adding a new "Shell Tool" target, but I don't know how to make it run like one. What build settings do I have to add to that target? What files (main.m?) do I need to start it up?
EDIT (Added my comments from below to hopefully make the question more answerable.)
My library has two targets, one for iOS and one for MacOS. I'm only including it in an iOS project so far, so that's the one I want work with presently. I tried adding a Cocoa Touch Unit Test Bundle target, but my build fails and I get command /bin/sh/ failed with exit code 1 and Failed tests for architecture 'i386' (GC OFF). I don't think I want to run on i386 (at least not for a test of my iOS target) and I can't find anything that says i386 in the target settings.
I see that my active architecture for the project is i386 (in the Project > Set Active Architecture menu), but it doesn't let me change it there. My TestApp target has Standard (armv6) as the architecture set and I tried searching the settings and nothing has i386 in it. How do I change that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Mac OS X SDK 中有一个单元测试捆绑目标的模板。
请注意,“捆绑包”是测试目标的构建产品:目标生成一个单元测试捆绑包。它不要求您的实际产品(库、应用程序等)是捆绑包;事实上,您的实际产品是什么并不重要。
也就是说,当您有静态库时,您可以采取一些不同的做法:
通常,您只需将被测代码的源代码文件添加到库目标和测试包目标中,但这样做也会测试您将测试包链接到库的能力。如果库存在任何阻止链接的问题,这可能会检测到它们。
There's a template for a unit-test bundle target in the Mac OS X SDK.
Note that the “bundle” is the build product of the test target: The target produces a unit-test bundle. It does not require that your actual product (library, app, etc.) be a bundle; in fact, it doesn't matter what your actual product is.
That said, you can do it a little differently when you have a static library:
Normally, you would just add the source code files for your code under test to both the library target and the test bundle target, but doing things this way also tests your ability to link the test bundle against the library. If the library has any problems that would prevent linking against it, this may detect them.
您可以更改活动的可执行文件吗? (它位于 Xcode 中的“项目”菜单下:设置活动可执行文件)
您的 Shell 工具目标在其构建文件之一中是否包含 int
main(int argc, char* argv[])
函数?Can you change the Active Executable? (it is under the Project menu in Xcode: Set Active Executable)
Does your Shell Tool target contain the int
main(int argc, char* argv[])
function in one of its built files?对于 Mac,您可以添加新目标。选择命令行工具模板。
For Mac, you can add a new target. Choose the command-line tool template.
在 XCode 9.1 中:
File ->新->目标...
MacOS 单元测试包
In XCode 9.1:
File -> New -> Target...
MacOS Unit Testing Bundle