version Build Swift Package Manager License
This macro eliminates boilerplate needed to set initial values of Dependency Injected instances' methods in unit tests.
By simply annotating a struct or class with @FatalTestValue, it auto-generates an initializer invoking fatalError() for the closure.
To get started, import FatalTestValue: import FatalTestValue, annotate your struct or class with @FatalTestValue:
import FatalTestValue @FatalTestValue struct Example { var create: @Sendable (Int) async throws -> Void var read: @Sendable (Int) async throws -> String var update: @Sendable (Int, String) async throws -> Void var delete: (Int) -> Void }
This will automatically generate an extension with a testValue property.
extension Example { public static let testValue = Example( create: { _ in fatalError() }, read: { _ in fatalError() }, update: { _, _ in fatalError() }, delete: { _ in fatalError() } ) }
If you are using GUI to set up Package Dependencies in Xcode, add the URL in Pacakge Dependencies.
https://github.com/CuriositySoftware/swift-fatal-test-value
If you are using Package.swift add:
.package( url: "https://github.com/CuriositySoftware/swift-fatal-test-value/", .upToNextMajor(from: "1.0.0") )
and then add the product to any target that needs access to the macro:
.product( name: "FatalTestValue", package: "swift-fatal-test-value" )