Error when running `swift test` in Playing Card example project

I am unable to run tests using the swift test command.

I tried cloning the Playing card example project (GitHub - apple/example-package-playingcard: Example package for use with the Swift Package Manager)

I am able to successfully build the project using swift build but when I run swift test, it outputs the following error:

error: cannot load underlying module for 'XCTest'

I had created an executable project and hence it had main.swift file. TIL that if you have main.swift in the same target then linking with tests fails.