Skip to content

Instantly share code, notes, and snippets.

@Kyome22
Last active April 16, 2022 07:45
Show Gist options
  • Save Kyome22/b80bbdb08ac0acbe84bef97294c79783 to your computer and use it in GitHub Desktop.
Save Kyome22/b80bbdb08ac0acbe84bef97294c79783 to your computer and use it in GitHub Desktop.
XCTContext.runActivities(setUp:tearDown:blocks:)
//
// XCTContext+Extension.swift
// TestEachTests
//
// Created by ky0me22 on 2022/04/07.
//
import XCTest
extension XCTContext {
typealias VoidClosure = () -> Void
typealias ThrowClosure = () throws -> Void
private static func runBlock(block: ThrowClosure) rethrows -> Void {
do {
try block()
} catch {
throw error
}
}
class func runActivities(
_ dummyClosure: ThrowClosure = {},
setUp: VoidClosure? = nil,
tearDown: VoidClosure? = nil,
_ blocks: ThrowClosure...
) rethrows {
try XCTContext.runBlock {
for block in blocks {
do {
setUp?()
try block()
tearDown?()
} catch {
throw error
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment