Home > database >  Xcode Unit Test binary files work in Simulator but not on device
Xcode Unit Test binary files work in Simulator but not on device

Time:12-13

I have a Unit Test for batch processing of data.

I have added the test data by dragging the files into the Test target (without the copy if needed option). When testing in Simulator, it can find the files just fine

In the Unit Test, I access the folder by doing

func readFolder(folderPath: String) -> [String] {
        
        let folderPath = "/\(folderPath)" "/\(subfolder)"

        var files = try! FileManager.default.contentsOfDirectory(atPath: Bundle(for: type(of: self)).resourcePath! folderPath)
        ...

However, once I run that test on my device I get

Failed to load test bundle from file:///private/var/containers/Bundle/Application/../Processing.app/PlugIns/ProcessingTests.xctest/: Error Domain=NSCocoaErrorDomain Code=3588 "dlopen(/var/containers/Bundle/Application/.../Processing.app/PlugIns/ProcessingTests.xctest/ProcessingTests, 0x0109): tried: '/var/containers/Bundle/Application/.../Processing.app/PlugIns/ProcessingTests.xctest/ProcessingTests' (code signature invalid (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001F1B0, codeBlobSize=0x00004C30 for '/private/var/containers/Bundle/Application/.../Processing.app/PlugIns/ProcessingTests.xctest/ProcessingTests'), '/usr/local/lib/ProcessingTests' (no such file), '/usr/lib/ProcessingTests' (no such file),

...

The bundle “ProcessingTests” couldn’t be loaded. Try reinstalling the bundle.

How can I access the files located in the Unit Tests without having to add them to the actual app target? I want to avoid this since I think it's best to isolate the tests as much as possible from the app itself so adding the test data to the test target makes more sense.

CodePudding user response:

The error message is misleading. I had to change the team for signing for the Test and everything worked out.

  • Related