Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Test an iOS Library Which Is Using UIKit

I would like to create a library for iOS applications which uses UIKit. Furthermore I would like to create unit tests for this library. Unfortunately my tests do not work because of UIKit ([UIFont systemFontOfSize:12.0] to be precise).

According to Apple's Unit Testing Guide there are two types of test cases: logic tests and application tests. Application tests seem to be the correct type for tests involving UIKit related stuff but I did not find out about how to set up application tests for libraries. Has anybody ever had the same problem and was able to solve it?

Thanks a lot!

like image 629
zlajo Avatar asked Nov 29 '11 10:11

zlajo


People also ask

Is UIKit a framework or library?

Overview. The UIKit framework provides the required infrastructure for your iOS or tvOS apps.

How do I test a Swift package?

If you have only a Package. swift , you can build and test via xcodebuild similar to how you would with a Xcode project. First, run xcodebuild -list to find valid schemes from the package. Then invoke xcodebuild with the desired scheme.

How do you do iOS UI testing?

Recording a UI TestFrom the debug bar, click the Record UI Test button. Xcode will launch the app and run it. You can interact with the element on-screen and perform a sequence of interactions for any UI test. Whenever you interact with an element, Xcode writes the corresponding code for it into your method.


1 Answers

I found a solution to this. You must add a new target to your project that is simply an empty application. Then use that application as your test host following the instructions for doing this with a regular application like here:

Why does instantiating a UIFont in an iphone unit test cause a crash?

like image 76
jasongregori Avatar answered Oct 06 '22 01:10

jasongregori