swalkner
swalkner

Reputation: 17359

Xcode: how to test main bundles .plist file content?

I'd like to ensure with unit tests that important values inside my main MyApp-Info.plist are there and correct. Is there a way to load that plist from within my unit test bundle?

Upvotes: 3

Views: 2471

Answers (2)

Mattie
Mattie

Reputation: 3028

You can include your Info.plist in the Unit test bundle as a resource as well. That way, there's no dependency on the host application. However, finding and loading the resource requires just a tiny bit of trickery that seems to always trip me up.

See this question for examples on how to do that from ObjC and Swift.

Upvotes: 1

Mats
Mats

Reputation: 8638

It depends on if you have set a host application for your test target. If there is no host application, then the file is not copied with the test.

If there is a host application you can get its plist contents with:

Swift:

Bundle.main.infoDictionary

Objective-C:

[[NSBundle mainBundle] infoDictionary]

Upvotes: 5

Related Questions