From 9d729437d1595df9fd431b5cd8dd8103471eb1e0 Mon Sep 17 00:00:00 2001 From: Sergey Rubanov Date: Sat, 28 May 2022 18:23:07 +0200 Subject: [PATCH] xctest --- ios-dns-lookup/.gitignore | 4 +- .../ios_dns_devUITests.swift | 60 +++++++++++++++++++ .../ios_dns_devUITestsLaunchTests.swift | 32 ++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITests.swift create mode 100644 ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITestsLaunchTests.swift diff --git a/ios-dns-lookup/.gitignore b/ios-dns-lookup/.gitignore index 32bf8fd..4170e1a 100644 --- a/ios-dns-lookup/.gitignore +++ b/ios-dns-lookup/.gitignore @@ -1,4 +1,6 @@ *.mobileprovision /node_modules -/dist +/dist/* +!/dist/ios-dns-dev.xctestplan +!/dist/ios-dns-devUITests package-lock.json diff --git a/ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITests.swift b/ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITests.swift new file mode 100644 index 0000000..090f54c --- /dev/null +++ b/ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITests.swift @@ -0,0 +1,60 @@ +// +// ios_dns_devUITests.swift +// ios-dns-devUITests +// +// Created by Sergey Rubanov on 28.05.2022. +// + +import XCTest + +func isValidIp(s: String) -> Bool { + let parts = s.split(separator: ".") + let nums = parts.compactMap { Int($0) } + return parts.count == 4 && nums.count == 4 && nums.filter { $0 >= 0 && $0 < 256}.count == 4 +} + +class ios_dns_devUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + let webView = app.webViews.element(boundBy: 0); + let input = webView.textFields.element(boundBy: 0) + let result = webView.staticTexts.element(boundBy: 0) + let button = webView.buttons["Submit"] + + button.tap() + sleep(1) + XCTAssertTrue(isValidIp(s: result.label)) + input.tap() + input.typeText("lol") + button.tap() + XCTAssertEqual(result.label, "unknown node or service") + + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() + } + } + } +} diff --git a/ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITestsLaunchTests.swift b/ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITestsLaunchTests.swift new file mode 100644 index 0000000..56c7a7f --- /dev/null +++ b/ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITestsLaunchTests.swift @@ -0,0 +1,32 @@ +// +// ios_dns_devUITestsLaunchTests.swift +// ios-dns-devUITests +// +// Created by Sergey Rubanov on 28.05.2022. +// + +import XCTest + +class ios_dns_devUITestsLaunchTests: XCTestCase { + + override class var runsForEachTargetApplicationUIConfiguration: Bool { + true + } + + override func setUpWithError() throws { + continueAfterFailure = false + } + + func testLaunch() throws { + let app = XCUIApplication() + app.launch() + + // Insert steps here to perform after app launch but before taking a screenshot, + // such as logging into a test account or navigating somewhere in the app + + let attachment = XCTAttachment(screenshot: app.screenshot()) + attachment.name = "Launch Screen" + attachment.lifetime = .keepAlways + add(attachment) + } +}