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

tests: improve tests that are supposed to throw #1430

Merged
merged 1 commit into from
Mar 3, 2020

Commits on Mar 3, 2020

  1. tests: improve tests that are supposed to throw

    Motivation:
    
    The
    
        do {
            try someOperation()
    	XCTFail("should throw") // easy to forget
        } catch error as SomethingError {
            XCTAssertEqual(.something, error as? SomethingError)
        } catch {
            XCTFail("wrong error")
        }
    
    pattern is not only very long, it's also very error prone. If you forget
    any of the XCTFails, you might not tests what it looks like
    
        XCTAssertThrowsError(try someOperation) { error in
            XCTAssertEqual(.something, error as? SomethingError)
        }
    
    is much safer and shorter.
    
    Modifcations:
    
    Do many of the above replaces.
    
    Result:
    
    Cleaner, shorter, and safer tests.
    weissi committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    27f7bdc View commit details
    Browse the repository at this point in the history