3

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?

swalkner
  • 16,679
  • 31
  • 123
  • 210

2 Answers2

4

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]
shim
  • 9,289
  • 12
  • 69
  • 108
Mats
  • 8,528
  • 1
  • 29
  • 35
1

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.

Mattie
  • 2,868
  • 2
  • 25
  • 40