4

First of all I'd like to say that I'm pretty new to this topic so I'm a bit confused on some general aspects of how it works. Basically I'm working on an iOS project which has two targets, one is the app itself which I'm developing and it is a front-end iOS client, one is a static library which the former developer used to define classes belonging to a back-end framework.

Both the files of the app itself (the client I'm working on) and the static library (the back-end framework) are in the same xcode project bundle. Even If I've never done the "setup procedure" of the static library anything seems to be working just fine on compilation.

Now the question is: I'm setting up unit tests because I'd like to start developing new features adopting a Test Driven Development approach, so one of the things I was struggling on was if I had to generate or not two separate test targets, one for the iOS app and one for the static library (since they're two separate targets), ore use one single test target for both the static library and the iOS App. So, reading on the internet to find a solution I discovered that, as even Apple suggests here , a common approach is to add the static library as a "sub-project" of the app project.

I'm just asking myself why and what is the difference with my current situation (one project, to targets, one of it is the static library). Are there any drawbacks? Should I reorganize the whole project?

4

2 回答 2

1

我的经验与 Apple 和常用方法一致。我建议将框架作为子项目。(我在查找标头时遇到了一些问题,但那是我对 Xcode 缺乏掌握,而不是过程中的缺陷。)

独立地为每个项目设置单元测试。这样,您的测试就符合您使用框架的目标:您已经成功地将框架与父项目完全解耦。

如果您在父项目中编写所有单元测试,当另一个项目需要该框架时会发生什么?你有两个选择。您不能测试框架,或者沿着原始父级字符串。做正确的事并分开你的测试。

我已经构建了一个名为SpiffyKit的开源框架,它有一个名为 SpiffyTester 的父项目。(我承认我没有进行太多单元测试,因为它都是 UI,没有逻辑。)它可以作为一个很好的起点示例。

于 2013-08-30T17:24:56.637 回答
-2

根据您的需要,您可以使用Pods、 static 或将其添加到项目中。如果您将库添加为“子项目”,那么当您同时处理 2 个项目时会很有用。例如,如果您向库中添加新内容,您只需编译库,瞧,您就可以访问项目中的新库。但是,如果您只是链接静态库,则必须打开该库的项目,然后构建然后在库中替换它并添加新的头文件,这需要大量的设置工作。

于 2013-08-30T16:50:14.150 回答