Output folder and temporary folder (TestLog)

in Japanese(日本語)

Returns the folders to use when a scenario writes files. Scenarios run inside a sandbox, so these two folders (and what is under them) are the only places a scenario can write. The locations returned by NSTemporaryDirectory() and FileManager.default.temporaryDirectory are not writable (the write fails with "You don’t have permission").

Properties

Property Description
TestLog.directoryForLog: URL The output folder of this test class: <report directory>/<run start yyyy-MM-dd_HHmmss>/<test class name>/. Shared by the scenarios of the class in one run. Kept with the reports.
TestLog.directoryForTemp: URL A temporary folder for this scenario only. Deleted when the scenario ends. Not shared with other scenarios running in parallel.

Each folder is created the first time it is read.

Example

@Test("Export the price list")
func S0010() {
    scenario {
        scene(1, "Save the list") {
            action {
                let csv = TestLog.directoryForLog.appendingPathComponent("prices.csv")
                try? "name,price\n".write(to: csv, atomically: true, encoding: .utf8)

                let work = TestLog.directoryForTemp.appendingPathComponent("unzipped")
                try? FileManager.default.createDirectory(at: work, withIntermediateDirectories: true)
            }
        }
    }
}

What is kept and what is deleted