Is it possible to have another @main for testing?

Before, when we could check:

Code Block swift
let isRunningTests = NSClassFromString("XCTestCase") != nil


And then load a "testing AppDelegate" instead of the app's one on main.swift, so you could avoid making extra configurations that just add overhead when running unit tests.

I think it's not possible to have 2 @main structs, how should we achieve this now?

Thank you.
Answered by in 615355022
You could use an environment variable. Edit your scheme and add an environment variable for testing e.g. isTesting = YES. In your app you can read from it using ProcessInfo.processInfo.environment["isTesting"] and perform your configuration based on the result.
Accepted Answer
You could use an environment variable. Edit your scheme and add an environment variable for testing e.g. isTesting = YES. In your app you can read from it using ProcessInfo.processInfo.environment["isTesting"] and perform your configuration based on the result.
Is it possible to have another @main for testing?
 
 
Q