Last active
April 16, 2022 07:45
-
-
Save Kyome22/b80bbdb08ac0acbe84bef97294c79783 to your computer and use it in GitHub Desktop.
XCTContext.runActivities(setUp:tearDown:blocks:)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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