[bundle infoDictionary] doesn't contain some keys in info.plist file.

I try to do unit test for an ES system extension's code using Unit Testing Bundle. 

the code tries to get NSEndpointSecurityMachServiceName in info.plist by [bundle objectForInfoDictionaryKey:] but failed. 

I have added NSEndpointSecurityMachService to info.plist of Test Bundle, and I did check info.plist file in bundle, NSEndpointSecurityMachServiceName was listed there.

Answered by DTS Engineer in 816961022

Unit test bundles are loaded and run by a running process. This is either your app or a Xcode-specific runner, depending on the Test Host build setting. If you call +mainBundle, that’s the bundle you get.

So, if you add a property to your test bundle’s Info.plist, you need to get a reference to it rather than the main bundle. The canonical way to da that is to call +bundleForClass: on a class that’s in your unit test bundle.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Unit test bundles are loaded and run by a running process. This is either your app or a Xcode-specific runner, depending on the Test Host build setting. If you call +mainBundle, that’s the bundle you get.

So, if you add a property to your test bundle’s Info.plist, you need to get a reference to it rather than the main bundle. The canonical way to da that is to call +bundleForClass: on a class that’s in your unit test bundle.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[bundle infoDictionary] doesn't contain some keys in info.plist file.
 
 
Q