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

前端 未结 6 985
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 05:18

I\'m trying to unit test some iphone code that instantiates fonts. I\'ve narrowed it down to the following crashing unit test:

#import \"test.h\"
#import &l         


        
6条回答
  •  萌比男神i
    2020-12-08 05:56

    Sorry for digging it up, but I have some issue with XCT test on Xcode 5 and it's related with this thread

    Quote:

    "Many UIKit classes won't work without the UIApplication Trying to add code to pass the tests in this project revealed that other tests would have to be conditionally excluded from LogicTests as well:

    The default loadView method will fail — so the testLoadView method is #ifdef'd out.

    Any attempt to alloc/init a UILabel will fail. I don't know why but because of this, all tests on the labels must be #ifdef'd.

    Generally, don't expect anything from the UIKit framework to work in your Logic tests. Other frameworks will almost always work (in this application, the CoreLocation and Foundation frameworks work without issue).

    Within UIKit, some elements will work — for example, UIWebView didn't have any issues in my testing. Exactly which user-interface objects will fail in the LogicTests bundle (without an actual running application) is never really clear until you try but these failures are why you still need to run the Application Tests to verify against — the Application Tests are a more authoritative result for anything in UIKit."

    URL: http://www.cocoawithlove.com/2009/12/sample-iphone-application-with-complete.html

提交回复
热议问题