Skip to content

Instantly share code, notes, and snippets.

@pfandrade
Last active October 22, 2017 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfandrade/10eb8e98d483d1f045035471bf9286cf to your computer and use it in GitHub Desktop.
Save pfandrade/10eb8e98d483d1f045035471bf9286cf to your computer and use it in GitHub Desktop.
Example setup and teardown in Secrets UI tests
class SecretsTouchUITests: XCTestCase {
var testDirectoryURL: URL!
var testDocumentURL: URL!
func documentName() -> String? {
return "testDoc1"
}
override func setUp() {
super.setUp()
self.continueAfterFailure = false
let folderURL = sharedFolderURL()
testDirectoryURL = temporaryDirectoryAtURL(folderURL)
if let docName = documentName() {
guard let docURL = Bundle(for: SecretsTouchUITests.self).url(forResource: docName, withExtension: "secrets") else {
XCTFail("Failed to get URL for \(docName). Are you sure you included it in the test bundle?")
fatalError()
}
testDocumentURL = testDirectoryURL.appendingPathComponent(docURL.lastPathComponent)
XCTAssertNoThrow( try FileManager.default.copyItem(at: docURL, to: testDocumentURL), "Failed to copy document to shared folder")
}
else {
self.testDocumentURL = testDirectoryURL.appendingPathComponent("NewDoc.secrets")
}
let app = XCUIApplication()
var args: [String] = []
args.append(contentsOf: ["-ResetDefaults", "YES"])
args.append(contentsOf: ["-com.apple.CoreData.ConcurrencyDebug", "1"])
if FileManager.default.fileExists(atPath: testDocumentURL.path) {
args.append(contentsOf: ["-OpenDocumentAt", testDocumentURL.path])
}
else {
args.append(contentsOf: ["-SetupNewDocumentAt", testDocumentURL.path])
}
app.launchArguments = args
app.launch()
}
override func tearDown() {
// Tidy up by removing the test directory
try? FileManager.default.removeItem(at: testDirectoryURL)
super.tearDown()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment