How do you know if you're running unit tests when calling swift test

I think in Swift 5.6 this works properly

#if canImport(XCTest)
  return
#else
  // do ordinary api calls
#endif

The downside being that you don't get compiler support for that else branch unless you're building in release configuration...

1 Like