Last active
October 22, 2017 21:24
-
-
Save pfandrade/10eb8e98d483d1f045035471bf9286cf to your computer and use it in GitHub Desktop.
Example setup and teardown in Secrets UI tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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