One annoying thing when running tests in Xcode 6.1 is that the entire app has to run and launch its storyboard and root view controller. In my app this runs some server calls th
This is the swift way to do it.
extension Thread {
var isRunningXCTest: Bool {
for key in self.threadDictionary.allKeys {
guard let keyAsString = key as? String else {
continue
}
if keyAsString.split(separator: ".").contains("xctest") {
return true
}
}
return false
}
}
And this is how you use it:
if Thread.current.isRunningXCTest {
// test code goes here
} else {
// other code goes here
}
Here is the full article: https://medium.com/@theinkedengineer/check-if-app-is-running-unit-tests-the-swift-way-b51fbfd07989