I'm using server-side Swift, and doing my development in Xcode after doing:
swift package generate-xcodeproj
I have a class that uses Bundle
(formerly NSBundle
) to load in a .plist file for some settings in the server. It works fine when running in the server itself, but when I create some unit tests for this class, I cannot get access to the directory where the .plist file is located. The relevant snippet of code is:
let bundlePath = Bundle.main.bundlePath as NSString
let plistPath = bundlePath.appendingPathComponent("Test.plist")
plistDict = NSDictionary(contentsOfFile: plistPath)
When I run this in unit XCTests, plistPath is:
/Applications/Xcode-8.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Agents/Test.plist
which is not very useful.
One thing that I've noticed is that there are no options for "Host Application:" under the General tab.
Thoughts?
I've not been able to fully answer this, but came up with a work-around for my situation. I'm using the Perfect File class (see https://github.com/PerfectlySoft/Perfect.git), and just dynamically creating the file I need for my XCTest cases in the setUp() method. Fortunately, I have fairly simple needs for file contents. Here's the initial part of my XCTest file:
See https://github.com/crspybits/SMServerLib for the full context.