NSURL to file path in test bundle with XCTest

后端 未结 8 1619
栀梦
栀梦 2020-12-23 18:35

I am trying to write an iOS app using TDD and the new XCTest framework. One of my methods retrieves a file from the internet (given a NSURL object) and stores it in the user

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 19:30

    In fact, the [NSBundle mainBundle] when running a UnitTest is not the path of your app, but is /Developer/usr/bin, so this will not work.

    The way to get resources in a unit test is here: OCUnit & NSBundle

    In short, use:

    [[NSBundle bundleForClass:[self class]] resourcePath]
    

    or in your case:

    [[NSBundle bundleForClass:[self class]] resourceURL]
    

提交回复
热议问题