NSURL to file path in test bundle with XCTest

后端 未结 8 1579
栀梦
栀梦 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:10

    Just to append to correct answer, this is example how to get filePath for a file in your UnitTests/Supporting Files:

    NSString *filePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"YourFileName.json"];
    XCTAssertNotNil(filePath);
    

    This probably will be useful for someone.

提交回复
热议问题