         case .off:
             addIndexStoreArguments = false
         case .auto:
-            addIndexStoreArguments = configuration == .debug
+            if configuration == .debug {
+                addIndexStoreArguments = true
+            } else if enableTestDiscovery && target.type == .test {
+                // Test discovery requires an index store for the test targets
+                // to discover the tests
+                addIndexStoreArguments = true
+            } else {
+                addIndexStoreArguments = false
+            }
         }
 
         if addIndexStoreArguments {

        case .release: break
        }

        args += buildParameters.indexStoreArguments
        args += buildParameters.toolchain.extraSwiftCFlags
        args += optimizationArguments
        args += ["-g"]

        result += buildParameters.targetTripleArgs(for: target)
        result += ["-swift-version", swiftVersion.rawValue]

        result += buildParameters.indexStoreArguments(for: target)
        result += buildParameters.toolchain.extraSwiftCFlags
        result += optimizationArguments
        result += ["-g"]
