DEV Community

David Goyes
David Goyes

Posted on

Swift Testing #14: Registrando fallas con Issue.record

XCTest tiene una función, XCTFail(), que genera una falla inmediata e incondicionalmente. Se usa esta función cuando, dada la lógica de una prueba, ciertas condiciones y cierto flujo de control, queremos que la prueba falle.

// Antes
class IssueTests_deprecated: XCTestCase {
  func testSomeIssue() {
    let a = Int.random(in: 0...1)
    if a > 0 {
      XCTFail("This should not occur")
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

En Swift Testing, para provocar que la prueba falle inmediata e incondicionalmente, usaríamos la función Issue.record(_:sourceLocation:) a la que podemos pasar un comentario y/o un posible error.

struct IssueTests {
  @Test
  func someIssue() {
    let a = Int.random(in: 0...1)
    if a > 0 {
      Issue.record("This should not occur")
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Bibliografía

  • Documentación sobre Swift Testing, aquí.
  • Documentación "Record issues", aquí.

Top comments (0)