How to generate writable path in FileManager that works in XCTest
Asked Answered
P

1

9

I am writing an XCTest that involves writing a file to disk. I am using an AppGroup to define the file path. This works fine running on device or simulator.

class func filePath()->URL {
    guard let path = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "my.app.group.id") else {
        fatalError("No File Path")
    }
    let filePath = path.appendingPathComponent("filename.json")
    return filePath
}

… However the containerURL doesn't return something in an XCTest environment. The test crashes.

How can I generate a temporary path that works for Unit Testing?

Peddle answered 16/12, 2017 at 20:16 Comment(0)
N
0

This might be too late, but what you can do is to insert TEST_HOST in your test's target under Build Settings.

Neuro answered 3/2, 2020 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.