Is it possible to unit test a static library project using XCode's SenTestingKit?

眉间皱痕 提交于 2019-11-30 17:36:33
Daniel

Due to the nature of static libraries, you can't perform application tests, which by the sound of it is what you are trying to do. However, you can perform logic tests.

You were correct in your observation about unit testing in the client application.

The Xcode template optionally includes unit tests, but if you go to the build settings for that unit test you will see it doesn't specify a test host or bundle loader. This is because of the nature of static libraries. They are not applications, they are libraries - so you can do logic tests, you cannot do application tests.

Application tests you may wish to perform on your static library may include the following scenario:

My library creates an SQLite database at runtime, I wish to perform a unit test to check everything is inserting and/or updating as expected.

In order to test this with unit tests, one must create another application which includes or otherwise is dependant of your library. This application then includes your library and application tests may then be set up there.

I actually just solved it. I had to copy all of the .m files in my project to the LogicTest target's 'Compile Sources'. As well as add the frameworks the sources reference to the 'Link Binary With Libraries' section of the target.

I hope this helps others

Yes, Xcode 4.2 has a template for Cocoa Touch Static Library with tests.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!