Last active
March 9, 2020 13:36
-
-
Save dnedrow/249f5ae40422ad670f81826bd855ab0c to your computer and use it in GitHub Desktop.
Implement this protocol if you need to check whether the application is running in an XCTest context.
This file contains hidden or 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
| // Created by Nedrow, David E on 2018-11-03. | |
| // Attribution 4.0 International (CC 4.0), see bottom. | |
| import Foundation | |
| /// Implement this protocol if you need to check whether the application is running in an XCTest context. | |
| /// Default implementations are provided. | |
| /// By their nature, these test–related queries can't themselves be exhaustively unit tested. | |
| protocol XCTestProtocol { | |
| /// Used to determine if the app is running in an XCTest context. | |
| var isRunningXCTest: Bool { get } | |
| /// Used to determine if the app is running in an XCUITest context. | |
| var isRunningXCUITest: Bool { get } | |
| } | |
| extension XCTestProtocol { | |
| var isRunningXCTest: Bool { | |
| return NSClassFromString("XCTest") != nil | |
| } | |
| var isRunningXCUITest: Bool { | |
| return NSClassFromString("XCUITest") != nil | |
| } | |
| } | |
| extension NSObject: XCTestProtocol {} | |
| // This work is licensed under Attribution 4.0 International (CC 4.0) | |
| // You are free to: | |
| // Share — copy and redistribute the material in any medium or format | |
| // Adapt — remix, transform, and build upon the material | |
| // for any purpose, even commercially. | |
| // | |
| // This license is acceptable for Free Cultural Works. | |
| // The licensor cannot revoke these freedoms as long as you follow the license terms. | |
| // See https://creativecommons.org/licenses/by/4.0/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment