On Oct 6, 2008, at 2:41 PM, Cyrus Najmabadi wrote:
I'm currently in the process of creating a cocoa framework that will allow you to read and write Google's
ProtocolBuffer format. The library has been written, and seems to be working ok, so i've moved on to the part where i want ot write a bunch of unit tests to verify behavior, and also to catch regressions. However, i've finding myself commonly blocked while trying to do this, and no amount of Googling has been able to get my through the issues i'm running into. I'm hoping that people here can help me
This issue you're running into is related to how Mac OS X deals with dynamic (shared) libraries, not really anything to do with unit testing.
At build time, a dynamic library gets an "install name" embedded within it that corresponds to the path at which it expects to be deployed. When another binary links against a library, the library's install name is copied into the binary, and the loader will attempt to locate the library at that path.
You're encountering this when trying to create unit tests, rather than when you're trying to use your library, because:
Right now i have the following structure:
ProtocolBuffers.xcodeproj
Contains all of the real code for the framework and produces ProtocolBuffers.framework
ProtocolBuffers-Test.xcodeproj
This has an external framework reference to the framework produced by the previous project.
You should create the unit test bundle target in the same project as the framework target it contains tests for. The unit testing infrastructure in Xcode is really designed to work with the tests alongside whatever they're testing, not in separate projects.
That way tests have full access to the internals of whatever they're testing — after all, internals and public interfaces should both be tested — and you don't have to mess about with copying code-under-test into the test bundle's build folder or anything like that.
-- Chris