         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 {

        // This feature is not widely available in OSS clang. So, we only enable
        // index store for Apple's clang or if explicitly asked to.
        if ProcessEnv.vars.keys.contains("SWIFTPM_ENABLE_CLANG_INDEX_STORE") {
            args += buildParameters.indexStoreArguments
        } else if buildParameters.triple.isDarwin(), (try? buildParameters.toolchain._isClangCompilerVendorApple()) == true {
            args += buildParameters.indexStoreArguments
        }

        if !buildParameters.triple.isWindows() {

    }

    /// Returns the compiler arguments for the index store, if enabled.
    fileprivate func indexStoreArguments(for target: ResolvedTarget) -> [String] {
        let addIndexStoreArguments: Bool
        switch indexStoreMode {
        case .on:
