Launching XCTests in LLDB from command line on macOS

Is there a way to run Swift tests from the command line in LLDB on macOS?

On Linux, I am able to do lldb .build/debug/MyPackageTests.xctest. On macOS, I run into two issues:

  1. .build/debug/MyPackageTests.xctest is not an executable, but a bundle and trying to run .build/debug/MyPackageTests.xctest/Contents/MacOS/MyPackageTests gives me an exec format error (my wild guess is that on macOS the tests are a static library which is dynamically loaded).
  2. macOS requires special privileges to attach to a process (as evidenced by Xcode requesting permissions when debugging a local executable) and I'm not sure how to grant these permissions to my shell or lldb. sudo DevToolsSecurity --enable is the only seemingly relevant thing I've found and that doesn't seem to work.

Does anyone in the community have ideas about what I can try next?

1 Like

@George I have same problem. A you have any idea/solution?

The VSCode extension has to do the same. It involves running XCTest executable you get with Xcode and including the .xctest bundle from the .build folder as a parameter.

I can’t remember the exact form of this, but I worked it out by running swift test —verbose to get the command line needed to run tests.