ios-snapshot-test-case: Incompatible with Xcode 11b4 and xctestplans

Version 6.1.0 appears to be incompatible with Xcode 11b4 after enabling xctestplans on my project per the following error I am receiving.

xctest (40204) encountered an error (Failed to load the test bundle. (Underlying error: The bundle “PrivateFrameworkTests” couldn’t be loaded because it is damaged or missing necessary resources. The bundle is damaged or missing necessary resources. dlopen_preflight(/Users/user/Library/Developer/Xcode/DerivedData/PrivateApp/Build/Products/Test-iphonesimulator/PrivateFrameworkTests.xctest/PrivateFrameworkTests): Library not loaded: /usr/lib/swift/libswiftXCTest.dylib
  Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/PrivateApp/Build/Products/Test-iphonesimulator/PrivateFrameworkTests.xctest/Frameworks/FBSnapshotTestCase.framework/FBSnapshotTestCase
  Reason: no suitable image found.

A sample project without ios-snapshot-test-case works with xctestplans but with test plans I’m unable to run my tests.

Disabling iOSSnapshotTestCase as a pod in my project allows my tests to proceed

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 23 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Im encountering the same issue with Xcode 11 beta 5, too. Will this be fixed by the time of the release of Xcode 11?

@pogramos FBSnapshotTestCase 5.0.2 can be made to successfully build and test in XCode 11 with any simulator device regardless of the OS.

Here is a regex to fix the pbxproj:

cat FBSnapshotTestCase.xcodeproj/project.pbxproj \
| tr "\n" "😁" | \
php -R ' 
$search1 = "/\"-framework\",😁\\t\\t\\t\\t\\tXCTest,😁/"; 
$replace1 = "\"-weak_framework\",😁\t\t\t\t\tXCTest,😁\t\t\t\t\t\"-weak-lXCTestSwiftSupport\",😁"; 
$replacement1 = preg_replace($search1, $replace1, $argn); 
$search2 = "/OTHER_LDFLAGS/"; 
$replace2 = "LIBRARY_SEARCH_PATHS = \"$(PLATFORM_DIR)/Developer/usr/lib\";😁\t\t\t\tOTHER_LDFLAGS"; 
$replacement2 = preg_replace($search2, $replace2, $replacement1);
print $replacement2;' \
| > temp; \
cat temp | tr "😁" "\\n" | \
> FBSnapshotTestCase.xcodeproj/project.pbxproj; \
rm temp

See also https://github.com/CocoaPods/CocoaPods/issues/9165#issuecomment-550273696

Basically Apple changed the dynamic libs for XCTest with XCode 11 / Swift 5.1. Older iOS device simulators may lack the right libraries inside their little brains. So you have to force them to know the New Truth, via yet more build setting cruft. It’s a joy.

Oh and why did I resort to changing newlines to smiley faces? Because unix is from the days of the telegram where newlines literally had hardware implications. There is this hang-up it has about newlines. OS X sed doesn’t handle multiline stuff without doing crazy things that no one can understand. It’s much easier to just replace all newlines with some random character at the beginning, then do your regex as if the file was one big line, then restore all the newlines at the end.

Alternatively rather than modifying & rebuilding the project, you can simply copy over the new XCTest library your older simulator and create a symlink so it gets used (that’s essentially what adding the above build-settings cruft does).

This did the trick for me, and is a lot more maintainable than modifying your carthage checkouts or whatever.

sudo zsh -c '
sourcedir="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib"; 
targetdir="/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 11.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib"; 
cp $sourcedir/libXCTestSwiftSupport.dylib $targetdir; 
cp -R $sourcedir/XCTest.swiftmodule $targetdir; 
cp $sourcedir/libXCTestBundleInject.dylib $targetdir;
ln -s $targetdir/libXCTestSwiftSupport.dylib $targetdir/libswiftXCTest.dylib'

We found that setting this build setting in FBSnapshotTestCase fixes the test bundle launch errors:

LIBRARY_SEARCH_PATHS = $(TOOLCHAIN_DIR)/usr/lib/swift-$(SWIFT_VERSION)/$(PLATFORM_NAME) $(inherited)

Where TOOLCHAIN_DIR is the path to XcodeDefault.xctoolchain and PLATFORM_NAME is, e.g. iphoneos

I’m experiencing the same problem using it to test on iOS 11.4 simulators, but it works fine on iOS 12 or later Even after updating to 6.2.0

Project.app (20066) encountered an error (Failed to load the test bundle. 
(Underlying error: The bundle “ProjectTest” couldn’t be loaded because it is damaged or missing necessary resources. 
The bundle is damaged or missing necessary resources. 
   dlopen_preflight(/Users/user/Library/Developer/Xcode/DerivedData/Project-cptrilskmcwcukcunmexqnpkrula/Build/Products/Debug-iphonesimulator/Project.app/PlugIns/ProjectTests.xctest/ProjectTests): 
   Library not loaded: /usr/lib/swift/libswiftXCTest.dylib

  Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Project-cptrilskmcwcukcunmexqnpkrula/Build/Products/Debug-iphonesimulator/Project.app/PlugIns/ProjectTests.xctest/Frameworks/FBSnapshotTestCase.framework/FBSnapshotTestCase
  Reason: no suitable image found.  Did find:
	/usr/lib/swift/libswiftXCTest.dylib: mach-o, but not built for iOS simulator))

already cleared my build folder, derived data and so on.

Maybe this will help? https://github.com/amrox/Bug-FBSnapshotTestCase-Xcode11

Please let me know if I can clarify anything. I’m going to keep hacking on it as well.

This is really interesting in that it only seems to affect iOS 11.4 simulators. iOS 12 and 13 work fine so perhaps this is an Xcode bug?

Is anyone else on this thread having the issues with iOS 12 or higher?