Unable to UnitTest Swift classes/struct/functions in a SPM command line app

I've run into a bit of a quandary, about why this fails to work, and I need to ask to find out if there is a reason for what I'm seeing. I can reproduce 100% of the time.

What I am trying to do:
  1. Use Swift Package Manager to generate a command line application target.

  2. Add a Swift class/struct/function to the project

  3. Add a UnitTest for validation

  4. Use SPM to create a new command line project:

Code Block
mkdir CommandLineTool
cd CommandLineTool
swift package init --type executable

2. Add a New File to CommandLineApp, let's call it Foo.swift:
Code Block
import Foundation
public struct Foo {
    public func message() -> String {
        return "Hello, World"
    }
}

Build, and everything works!

3. Add a new UnitTest swift class FooTests.swift:
Code Block
import XCTest
@testable import CommandLineTool
final class FooTests: XCTestCase {
    func testFooMessage() {
        let message = Foo().message()
        XCTAssertTrue(message == "Hello, world!")
    }
}


Build Error:
Code Block
Undefined symbol: CommandLineTool.Foo.message() -> Swift.String
Undefined symbol: CommandLineTool.Foo.init() -> CommandLineTool.Foo


Questions:
  1. Why does this fail?

  2. Why can I not add a UnitTest for items added to a command line SPM project?

Other Observations:
  • The same process also fails, if I use Xcode 12.4 to generate a Command Line Tool project for macOS.

  • Doing the exact same process is successful if I use one of the following:

    • Use SPM to generate a library, and I add a new Unit Test.

    • Use Xcode 12.4 to generate a macOS UI based App or iOS app project, then add in a UnitTest for a new swift file I add to the main application.

Why can we not add unit tests to a Command Line Tool project, or a SPM based command line app?

Thank you for any help with this.
Unable to UnitTest Swift classes/struct/functions in a SPM command line app
 
 
Q