XCTestCase

extension XCTestCase
  • Executes the testcase closure and expects it to produce a specific assertion failure.

    Declaration

    Swift

    public func expectAssertionFailure<T: Error>(
        expectedError: T,
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    ) where T: Equatable

    Parameters

    expectedError

    The Error you expect testcase to pass to assert() or assertionFailure().

    timeout

    How long to wait for testcase to produce its error. Defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it to produce a specific assertion failure message.

    Declaration

    Swift

    public func expectAssertionFailure(
        expectedMessage message: String,
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    message

    The String you expect testcase to pass to assert().

    timeout

    How long to wait for testcase to produce its error. Defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it to produce any assertion failure.

    Declaration

    Swift

    public func expectAssertionFailure(
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    timeout

    How long to wait for testcase to produce its error. Defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it finish without producing any assertion failures.

    Declaration

    Swift

    public func expectNoAssertionFailure(
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    timeout

    How long to wait for testcase to finish. Defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run.

  • Executes the testcase closure and expects it to produce a specific fatal error.

    Declaration

    Swift

    public func expectFatalError<T: Error>(
        expectedError: T,
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    ) where T: Equatable

    Parameters

    expectedError

    The Error you expect testcase to pass to fatalError().

    timeout

    How long to wait for testcase to produce its error. defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it to produce a specific fatal error message.

    Declaration

    Swift

    public func expectFatalError(
        expectedMessage message: String,
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    message

    The String you expect testcase to pass to fatalError().

    timeout

    How long to wait for testcase to produce its error. defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it to produce any fatal error.

    Declaration

    Swift

    public func expectFatalError(
        timeout: TimeInterval = 2,
        in context: StaticString = #function,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    timeout

    How long to wait for testcase to produce its error. defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it execute without producing any fatal errors.

    Declaration

    Swift

    public func expectNoFatalError(
        timeout: TimeInterval = 2,
        in context: StaticString = #function,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    timeout

    How long to wait for testcase to finish. Defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run.

  • Executes the testcase closure and expects it to produce a specific precondition failure.

    Declaration

    Swift

    public func expectPreconditionFailure<T: Error>(
        expectedError: T,
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    ) where T: Equatable

    Parameters

    expectedError

    The Error you expect testcase to pass to precondition().

    timeout

    How long to wait for testcase to produce its error. defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it to produce a specific precondition failure message.

    Declaration

    Swift

    public func expectPreconditionFailure(
        expectedMessage message: String,
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    message

    The String you expect testcase to pass to precondition().

    timeout

    How long to wait for testcase to produce its error. defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it to produce any precondition failure.

    Declaration

    Swift

    public func expectPreconditionFailure(
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    timeout

    How long to wait for testcase to produce its error. defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run that produces the error.

  • Executes the testcase closure and expects it finish without producing any precondition failures.

    Declaration

    Swift

    public func expectNoPreconditionFailure(
        timeout: TimeInterval = 2,
        file: StaticString = #file,
        line: UInt = #line,
        testcase: @escaping () -> Void
    )

    Parameters

    timeout

    How long to wait for testcase to finish. Defaults to 2 seconds.

    file

    The test file. By default, this will be the file from which you’re calling this method.

    line

    The line number in file where this is called.

    testcase

    The closure to run.