     private var optimizationArguments: [String] {
         switch buildParameters.configuration {
         case .debug:
-            return ["-Onone", "-enable-testing"]
+            return ["-Onone"]
         case .release:
             return ["-O"]
+        }
+    }
+
+    /// Testing arguments according to the build configuration.
+    private var testingArguments: [String] {
+        switch buildParameters.configuration {
+        case .debug:
+            return ["-enable-testing"]
+        case .release:
+            if self.buildParameters.enableTestDiscovery {
+                return ["-enable-testing"]
+            } else {
+                return []
+            }
         }
     }
 

        result += buildParameters.targetTripleArgs(for: target)
        result += ["-swift-version", swiftVersion.rawValue]
        result += optimizationArguments
        result += ["-g"]
        result += ["-j\(ProcessInfo.processInfo.activeProcessorCount)"]
        result += activeCompilationConditions

        result += buildParameters.indexStoreArguments(for: target)
        result += buildParameters.toolchain.extraSwiftCFlags
        result += optimizationArguments
        result += testingArguments
        result += ["-g"]
        result += ["-j\(ProcessInfo.processInfo.activeProcessorCount)"]
        result += activeCompilationConditions
