 
     private let configuration = "debug"  //FIXME should swift-test support configuration option?
 
+    /// Builds the "test" target if enabled in options.
+    private func buildTestsIfNeeded(_ opts: TestToolOptions) throws {
+        let yamlPath = opts.path.build.appending(RelativePath("\(configuration).yaml"))
+        if opts.buildTests {
+            try build(yamlPath: yamlPath, target: "test")
+        }
+    }
+
     /// Locates the XCTest bundle on OSX and XCTest executable on Linux.
     /// First check if <build_path>/debug/<PackageName>Tests.xctest is present, otherwise
     /// walk the build folder and look for folder/file ending with `.xctest`.

        let packageName = opts.path.root.basename  //FIXME probably not true
        let maybePath = opts.path.build.appending(RelativePath(configuration)).appending(RelativePath("\(packageName)Tests.xctest"))

        if maybePath.asString.exists {
            return maybePath
        } else {
            let possiblePaths = walk(opts.path.build.asString).filter {
                $0.basename != "Package.xctest" &&   // this was our hardcoded name, may still exist if no clean

        return (mode ?? .run(nil), opts)
    }

    /// Executes the XCTest binary with given arguments.
    ///
    /// - Parameters:
    ///     - path: Path to a valid XCTest binary.
    ///     - xctestArg: Arguments to pass to the XCTest binary.
    ///
    /// - Returns: True if execution exited with return code 0.
    private func test(path: AbsolutePath, xctestArg: String? = nil) -> Bool {
        precondition(isValidTestPath(path))

        var args: [String] = []
      #if os(OSX)
