Make SwiftPM run XCTest and Testing tests in parallel by default?

Despite my opposition to changing the default behavior, I do think it would useful to add a mechanism to the SwiftPM manifest (Package.swift) format to explicitly declare that a .testTarget should always run in parallel, including its XCTest tests (if it contains any).

This would remain completely opt-in, preserving existing behavior by default. The main benefit is that users would not need to remember to pass the --parallel flag to swift test, or know whether it is safe to do so in advance, because test targets with that setting would automatically be parallelized. Plus, having it be a target-level setting means it would be more granular, so any test targets which aren't suitable for parallelization could remain serialized.

Conceptually, I think it would be best expressed as a tri-state setting like:

enum ParallelizationBehavior {
  /// Each testing library should use its default behavior.
  /// (Swift Testing: true; XCTest: false).
  /// This is the default parallelization behavior.
  case automatic

  /// Enable parallelization whenever it is supported.
  /// (Not all testing libraries may support parallelization, or may
  /// only support it on certain platforms or environments.)
  case enabledIfSupported

  /// Completely disable parallelization, even when it is
  /// possible to support it.
  case disabled
}

// Usage example:
.testTarget(
  name: "MyTests",
  ...
  parallelization: .enabledIfSupported
)
4 Likes