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

Unit Test #383

Open
mazingyu opened this issue Mar 25, 2021 · 1 comment
Open

Unit Test #383

mazingyu opened this issue Mar 25, 2021 · 1 comment

Comments

@mazingyu
Copy link

Pass: invalidhost is reachable - Reachability.Reachability

@mazingyu
Copy link
Author

mazingyu commented Mar 25, 2021

`
func testValidHost() {
let validHostName = "invalidhost"

    guard let reachability = try? Reachability(hostname: validHostName) else {
        return XCTFail("Unable to create reachability")
    }
    
    let expected = expectation(description: "Check valid host")
    reachability.whenReachable = { reachability in
        print("Pass: \(validHostName) is reachable - \(reachability)")
        expected.fulfill()
        // Only fulfill the expectation on host reachable
    }
    reachability.whenUnreachable = { reachability in
        print("\(validHostName) is initially unreachable - \(reachability)")
        // Expectation isn't fulfilled here, so wait will time out if this is the only closure called
    }
    
    do {
        try reachability.startNotifier()
    } catch {
        return XCTFail("Unable to start notifier")
    }
    
    waitForExpectations(timeout: 5, handler: nil)
    
    reachability.stopNotifier()
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant