XCTest - adding source files to test target vs using Host Application

In Xcode 14, there seem to be two ways to configure how any particular piece of source code from the app module is available in a test target:

  1. Add the source file to both the app target and the test target
  2. Add the source file only to the app target, import the app module into each test class, and configure the test target to run use the app as the Host Application (including checking the 'Allow testing Host Application APIs' checkbox)

Going with the first method seems to be better in my testing, as it produces a much faster run time. Option (2) when using the default (and very much desired) parallelization setting causes multiple simulator launches, which slows things down terribly.

The downside of option (1) is that we'll be compiling source files twice. We really want to be testing precisely what was compiled in the app module, but it seems the lesser issue to contend with.

So, neither of these options seem ideal to me – what we really want is a dumb anonymous test target that simply links to the compiled app module. This would avoid the extra compile step, allow me to avoid using a Host Application, and test precisely what's compiled into the app module.

Am I missing something, or is there no way to achieve this?

A third option — and it’s hard to say whether it’s a better option, it really does depend on your specific circumstances — is to put the code you want to test into a framework, where you can access it from the framework’s test target and the app.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

XCTest - adding source files to test target vs using Host Application
 
 
Q