CFBundleShortVersionString returns Xcode version number in unit testing

We're using the function defined bellow to get the version of the app.

extension Bundle {
   public static var appVersion: String? {
      main.object(forInfoDictionaryKey:    "CFBundleShortVersionString") as? String
   }
}

Since the release of Xcode 13, our test fails because CFBundleShortVersionString returns current Xcode version instead of null. Before it was returning null and we were assigning it default value during unit tests. Is this intended behaviour or an issue which we can expect to be fixed?

Answered by DTS Engineer in 692983022

If you go to the General tab of the test target editor, what do you have set for Host Application?

Share and Enjoy

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

Accepted Answer

If you go to the General tab of the test target editor, what do you have set for Host Application?

Share and Enjoy

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

Was this Host Application always there?

Yes.

Before Xcode 13 we were getting null but now we were getting the Xcode version.

If you have no Host Application set then your unit tests are loaded in a host process provided by Xcode. I suspect that on earlier versions of Xcode this didn’t have a CFBundleShortVersionString string in its Info.plist (or perhaps it has no Info.plist at all) and so you’d get back nil.

Share and Enjoy

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

Hi, we have a similar problem, from Xcode 13, the Xcode version is returned when getting CFBundleShortVersionString. But our host application has to remain as None since we are testing SDK, not an app. Is there any other way, how we can affect, what will be returned? We do not want to hardcode the Xcode version as a string in our tests. Thanks for any ideas 🙏🏻

CFBundleShortVersionString returns Xcode version number in unit testing
 
 
Q