Structures

The following structures are available globally.

  • Stops execution of test when thrown inside an it block, emitting a failure message.

    Unlike other errors that can be thrown during a test, StopTest represents an expected failure, with the failure description tied to the file and line it is thrown on.

    Tests can also be stopped silently by throwing StopTest.silently.

    The primary use case of StopTest as opposed to normal error logging is when a condition is critical for the remainder of the test. It serves as an alternative to force unwrapping or out-of-range subscripts that could be cause the test to crash.

    For example,

    guard let value = getValue() else {
        throw StopTest("Got a null value from `getValue()`)
    }
    

    When used with Nimble, any expectation can stop a test by adding .onFailure(throw: StopTest.silently).

    For example,

    try expect(array).toEventually(haveCount(10)).onFailure(throw: StopTest.silently)
    
    See more

    Declaration

    Swift

    public struct StopTest : Error
  • A property wrapper that will automatically reset the contained value after each test.

    See more

    Declaration

    Swift

    @propertyWrapper
    public struct TestState<T>