Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xctest #20

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ios-dns-lookup/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.mobileprovision
/node_modules
/dist
/dist/*
!/dist/ios-dns-dev.xctestplan
!/dist/ios-dns-devUITests
package-lock.json
60 changes: 60 additions & 0 deletions ios-dns-lookup/dist/ios-dns-devUITests/ios_dns_devUITests.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}